Previously, I've been able to open a directory in VS Code by running code .
in the terminal. I'm not sure when it stopped working but recently it has. I'm running on MacOS 12.3 beta 2.
I have Python 3.9.10 installed via Homebrew. Brew says all the symlinks are linked but I'm not so sure. Just running regular python -V
no longer is valid, I can only run via python3 -V
I have run the command from inside VS Code Shell Command: Install 'code' command in PATH
multiple times to no avail.
CodePudding user response:
In macOS 12.3 beta Apple removed support for Python 2. Additionally Python 3 no longer comes bundled with macOS. This causes the code command to not work anymore.
makaracc has provided a solution:
cd /usr/local/bin
nano code
change python => python3 on the following line
- function realpath() { python -c ...
function realpath() { python3 -c ...
And you can wait for the update.
You can refer to this page for more details.
CodePudding user response:
My symlink looks like this:
code -> /Users/myUserName/OtherApplications/Visual Studio Code.app/Contents/Resources/app/bin/code
Double check the path to code, which code
will do it.
If that fails, then it's not in your path.
If your symlink, and your path to it are both correct you should be ready to go. If you need to make a new symlink ln -s [file_you_want_to_link_to] [the_name_of_your_new_link]
If you need to find the executable: From your home directory (just cd
and hit enter will take you there) and if, like me, your VS Code is installed under your home directory, find ~ -type f -name code
will find it.
If it's installed system-wide, then find /Applications/ -type f -name code
will find it there.
Once you find the executable, use the above ln -s
command to make a symlink, but do it from somewhere in your path.
I simplify my life by creating my own bin directory for all my little scripts right in my home directory. I call mine "mybin" and used mkdir ~/mybin
to create it. In my .bash_profile (in my home directory) I have a line like this: export PATH="$PATH:/Users/myUserName/homebrew/bin:/Users/myUserName/mybin"
Which is where my symlink to code lives. :)
Once you locate code and make a symlink to it somewhere in your path, code .
should work again.
To make my symlink, I did this from inside
~/mybin ln -s "/Users/myUserName/OtherApplications/Visual Studio Code.app/Contents/Resources/app/bin/code" code
(I needed to put the path to code in quotes because it has spaces in it).