简体   繁体   English

python2.7:brew升级python3后没有这样的文件或目录

[英]python2.7: no such file or directory after brew upgrade python3

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 .在执行brew updatebrew upgrade python3 ,我一直有这样的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 .首先,从 Homebrew 1.5 开始python3配方被重命名为python ,并且python配方现在可以作为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.虽然brew试图让它像魔术一样工作,但如果你有一个非常旧的安装,或者只是一个非常复杂的设置,使用来自 Homebrew 的pythonpython3 ,并且你brew upgrade python3 ,你最终只能得到新的 (3 .x) python配方在你期望的地方。

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.其次,您可能已经将 virtualenv 安装到非 Homebrew Python 中,它对在哪里找到东西感到困惑。

The easiest fix here is to uninstall that virtualenv and pip install it with the Homebrew 3.x Python.这里最简单的解决方法是卸载该virtualenv并使用 Homebrew 3.x Python pip install它。

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.更一般地说,如果您有除 Homebrew 3.7、Homebrew 2.7 和 Apple 预装的 2.7 之外的其他 Python 版本,除非您有充分的理由需要它们,否则您可能想要废弃它们。 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.而且,如果您已经将任何其他 Python 包安装到 Apple 的 2.7 中,您可能想要卸载它们并确保永远不要接触 Apple 安装并且只使用 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 .或者,如果您确实需要安装大量 Python,您应该习惯于使用<specific-python> -m tool而不是tool来运行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.很难让所有不同的脚本和符号链接保持同步,而且很容易最终使用一个你认为与python匹配但实际上安装到一个完全不同的pip中的pip ,以及一个使用另一个的virtualenv ,等等。

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:这是因为, virtualenvpython版本不同步,但是pythonpip仍然在一起:

$ 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. pythonpip都是 3.7,但virtualenv预计是 2.7。

Un and Reinstall using pip (which expected 3.7) resulted in a virtualenv in the same version.使用pip (预期为 3.7) virtualenv和重新安装导致相同版本的virtualenv

尝试了一些不起作用的事情..在我的情况下,这是有效的:

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.在我的情况下,修复是删除~/.indy directory ,这迫使indy重建符号链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM