`python3.7:糟糕的解释器:没有这样的文件或目录`


1

我在TensorFlow的本指南中安装了Python,pip3和virtualenv :

brew install python
pip3 install -U virtualenv

然后我能够创建一个虚拟环境:

virtualenv --system-site-packages -p python3 ./venv

然后我尝试安装TensorFlow

pip install --upgrade tensorflow

但它失败了,因为TensorFlow还不兼容Python 3.7。所以我brew remove python安装程序中删除了Python 3.7 并安装了3.6.7 。但是virtualenv现在运行相同的命令失败:

$ virtualenv --system-site-packages -p python3 ./venv
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

因此virtualenv,即使在删除之后,可执行文件的链接也会列出最新的Python版本。

此外,virtualenv列表brew作为用户组,这也令人困惑:

$ ls -la /usr/local/bin/virtualenv
-rwxr-xr-x  1 user  brew  232 29 Nov 17:06 /usr/local/bin/virtualenv

我试着卸载virtualenvpippip3我得到:

Skipping virtualenv as it is not installed.

我该如何解决这个问题?

Answers:


1

几个小时后,一个解决方案是virtualenv再次安装pip,然后将其删除pip

$ ls -la /usr/local/bin/virtualenv
-rwxr-xr-x  1 user  brew  232 29 Nov 17:06 /usr/local/bin/virtualenv
$ pip install virtualenv
...
$ pip uninstall virtualenv
...
$ which virtualenv
$ ls -la /usr/local/bin/virtualenv
ls: /usr/local/bin/virtualenv: No such file or directory

然后再次安装pip3

$ pip3 install virtualenv
Collecting virtualenv
...
Installing collected packages: virtualenv
Successfully installed virtualenv-16.1.0

请注意TensorFlow指向的使用pip3,而不是pip此链接不同。

现在创建虚拟环境的工作原理:

$ virtualenv --system-site-packages -p python3 ./venv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in ~/venv/bin/python3
Also creating executable in ~/venv/bin/python
Installing setuptools, pip, wheel...
done.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.