I have researched this for hours to no avail.
I think I deleted my directory at /usr/bin/python when I installed python 3 because I get this error: -bash: /usr/bin/python: No such file or directory.
I've tried sudo ln -s /usr/bin/python2.7 /usr/bin/python
, and that gives me ln: /usr/bin/python: File exists
However, it still doesn't permanently install a directory in /usr/bin/python. How do I permanently restore this directory?
I'm on a mac.
Thanks!
Install your “dev” Python into /usr/local/python-x.y.z or a similar location. Setup your shell (e.g. path variable and aliases) so that “python” and “python3” will run your preferred version. In scripts, use #!/usr/bin/python3 to run with system Python. Use #!/usr/bin/env python3 to run with your dev version.
By specifying #!/usr/bin/python you specify exactly which interpreter will be used to run the script on a particular system. This is the hardcoded path to the python interpreter for that particular system. The advantage of this line is that you can use a specific python version to run your code.
Your file /usr/bin/python exists because you get the message:
ln: /usr/bin/python: File exists
but I see that it is a corrupted link to something that doesn't exist, because you get the message:
-bash: /usr/bin/python: No such file or directory
What you have to do to fix that is:
sudo rm /usr/bin/python # because that's a corrupted file
sudo ln -s /usr/bin/python2.7 /usr/bin/python # this line will work if your file /usr/bin/python2.7 is OK.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With