启动终端时出现此错误:
Last login: Thu Apr 9 19:49:08 on ttys001
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/2.7/bin/python and that PATH is
set properly.
dhcp-128-189-78-23:~ user_me$
我需要将我的虚拟环境“指向”我正在使用的python版本。
我该怎么做?
答案 0 :(得分:11)
我有同样的问题,更新我的路径没有任何帮助,也没有设置VIRTUALENVWRAPPER_PYTHON和VIRTUALENVWRAPPER_VIRTUALENV。这是因为我在运行我的python版本时看到了这种奇怪的行为:
$ /usr/local/bin/python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.executable
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
我能够通过使用brew卸载python,使用brew重新安装python并强制它覆盖/ usr / local / bin中的现有符号链接来解决所有问题。
$ brew uninstall --force python
$ brew install python
$ brew link --overwrite python
$ brew linkapps python
$ pip install --upgrade pip setuptools
$ sudo pip uninstall virtualenv
$ pip install virtualenv
$ sudo pip uninstall virtualenvwrapper
$ pip install virtualenvwrapper
希望您在六个月前遇到这个问题时能够解决这个问题。我希望发布我的解决方案以防其他人遇到同样的问题,并且无法通过设置路径和env变量来解决它。
答案 1 :(得分:10)
virtualenvwrapper install guide中发现了以下内容。您可以尝试这样设置$ PATH正确。
要覆盖$ PATH搜索,请将变量VIRTUALENVWRAPPER_PYTHON设置为要使用的解释器的完整路径,并将VIRTUALENVWRAPPER_VIRTUALENV设置为要使用的virtualenv二进制文件的完整路径。必须在采购virtualenvwrapper.sh之前设置这两个变量。例如:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
答案 2 :(得分:0)
今天,经过一系列步骤,我得到了这个错误,第一步是安装wormhole
(https://magic-wormhole.readthedocs.io/en/latest/welcome.html#example),它安装了Python 3.8。
我开始遇到其他错误,我解决了brew uninstall python@2
brew uninstall python@2
Uninstalling /usr/local/Cellar/python@2/2.7.15_2... (4,814 files, 84.8MB)
python@2 HEAD_3 is still installed.
Run `brew uninstall --force python@2` to remove all versions.
brew uninstall --force python@2
Uninstalling python@2... (822B)
这时出现了这个问题的错误:
Last login: Wed May 27 11:33:08 on ttys025
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
我的解决方法是:
ls -l /usr/local/bin/python3
lrwxr-xr-x 1 neo admin 34 Nov 27 16:46 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
ln -s ../Cellar/python/3.7.5/bin/python3 /usr/local/bin/python
现在错误似乎消失了。
我不确定这是否是一个好的解决方案,我对那些比我更了解/了解brew
的人的反馈很感兴趣。
答案 3 :(得分:0)
我曾经使用 brew install multi version python,但我使用本地 python 创建的 virtualenv,因为我更新了我的 mac os 版本,发生了一些错误。出现以下错误,我的 virtualenv 无法正常工作。
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenvwrapper
我所做的事情让我的环境恢复了。
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python get-pip.py
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -m pip install virtualenvwrapper