After doing brew update
and brew upgrade python3
, I've been having such as bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
. eg:
⇒ mkvirtualenv --python=/usr/local/bin/python3 labrador
mkvirtualenv:78: /usr/local/bin/virtualenv: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
write() failed: Bad file descriptor
There are two possibilities here.
First, as of Homebrew 1.5 , the python3
recipe was renamed python
, and the python
recipe is now available as python@2
. See the current docs on how things are organized.
While brew
tries to make this just work like magic, if you had a really old install, or just a really complicated setup, with both python
and python3
from Homebrew, and you brew upgrade python3
, you can end up with only the new (3.x) python
recipe where you expect it to be.
To fix this one:
brew install python@2
Second, you may have had a virtualenv installed into a non-Homebrew Python that's confused about where to find things.
The easiest fix here is to uninstall that virtualenv
and pip install
it with the Homebrew 3.x Python.
More generally, if you have other Python versions besides Homebrew 3.7, Homebrew 2.7, and Apple pre-installed 2.7, unless you have a good reason to need them, you might want to scrap them. And also, if you've installed any other Python packages into Apple's 2.7, you might want to uninstall those and make sure to never touch the Apple install and only use the Homebrew 2.7.
Or, if you do need lots of Python installs around, you should get used to running tools with <specific-python> -m tool
instead of just tool
. It's hard to keep all the different script and symlinks in sync, and way too easy to end up using a pip
that you think matches python
but actually installs into a completely different one, and a virtualenv
that uses yet another one, and so on.
Solution in my case was:
pip uninstall virtualenv
pip install virtualenv
This was because, version of virtualenv
and python
were out of sync, but python
and pip
were still together:
$ virtualenv
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
$ python --version
Python 3.7.0
$ pip --version
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
Both python
and pip
are 3.7, but virtualenv
expected 2.7.
Un and Reinstall using pip
(which expected 3.7) resulted in a virtualenv
in the same version.
尝试了一些不起作用的事情..在我的情况下,这是有效的:
cd /usr/local/opt/python/bin/ ln -nfs /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/bin/python python2.7
I had a similar issue:
pre-commit is not in your $PATH; setting one up for you
Using virtualenv: /Users/jwilliams/.indy/venvs/pre-commit-venv_macosx-10.13-x86-64_cp2.7
$ cd /Users/jwilliams/repos/terraform-aws; /Users/jwilliams/.indy/venvs/pre-commit-venv_macosx-10.13-x86-64_cp2.7/bin/pre-commit install -f --install-hooks
dyld: Library not loaded: @executable_path/../.Python
Referenced from: /Users/jwilliams/.indy/venvs/pre-commit-venv_macosx-10.13-x86-64_cp2.7/bin/python2.7
Reason: image not found
$ cd /Users/jwilliams/repos/terraform-aws; /Users/jwilliams/.indy/venvs/pre-commit-venv_macosx-10.13-x86-64_cp2.7/bin/pre-commit install -f --install-hooks --hook-type pre-push
dyld: Library not loaded: @executable_path/../.Python
Referenced from: /Users/jwilliams/.indy/venvs/pre-commit-venv_macosx-10.13-x86-64_cp2.7/bin/python2.7
Reason: image not found
I followed the above steps and got the same error. The fix in my case was to delete the ~/.indy directory
, and this forced indy
to rebuild symlinks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.