mkvirtualenv ImportError: No module named stevedore 创建虚拟环境时出现错误:找不到 stevedore 模块。

6

我有一台装有Python和virtualenvwrapper的Mac电脑。我正在尝试通过以下方式创建一个新环境:

mkvirtualenv Test

To which I get the following error:

New python executable in /Users/sidharthnayyar/.virtualenvs/Test/bin/python
Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
        exec code in run_globals
    File "/Library/Python/2.7/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
        from stevedore import ExtensionManager
ImportError: No module named stevedore

我已在此安装了Python:

$ which -a python
    /usr/local/bin/python
    /usr/bin/python

如果我尝试使用sudo pip install stevedore命令,则会显示已安装该软件包,并附有一些警告信息:
sudo /usr/local/bin/pip install stevedore
The directory '/Users/sidharthnayyar/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/sidharthnayyar/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): stevedore in ./Library/Python/2.7/lib/python/site-packages
Requirement already satisfied (use --upgrade to upgrade): pbr>=1.6 in /Library/Python/2.7/site-packages (from stevedore)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9.0 in ./Library/Python/2.7/lib/python/site-packages (from stevedore)

如果我尝试使用sudo -H pip install stevedore,那么我会得到以下错误:
sudo -H /usr/local/bin/pip install stevedore

Collecting stevedore
    Using cached stevedore-1.18.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): pbr>=1.6 in /Library/Python/2.7/site-packages (from stevedore)
Collecting six>=1.9.0 (from stevedore)
    Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, stevedore
    Found existing installation: six 1.4.1
        DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
        Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
        prefix=options.prefix_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 736, in install
        requirement.uninstall(auto_confirm=True)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 742, in uninstall
        paths_to_remove.remove(auto_confirm)
    File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
        renames(path, new_path)
    File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
        shutil.move(old, new)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
        copy2(src, real_dst)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
        copystat(src, dst)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
        os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-NOex2K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

如果我创建了一个.bash_profile文件,并将以下内容放入其中:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

当我重新打开终端窗口时,我遇到了以下错误:
source ~/.bash_profile
Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
        exec code in run_globals
    File "/Library/Python/2.7/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
        from stevedore import ExtensionManager
ImportError: No module named stevedore
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/local/bin/python and that PATH is
set properly.

好奇而更加好奇。

有什么关于这个问题出错的建议和如何解决的方法吗?

谢谢 Sidharth


可能是重复问题:https://dev59.com/OoHba4cB1Zd3GeqPNiu6? - sberry
嗨,谢谢你的回复。不幸的是,我已经尝试了所有建议,但似乎对我没有用。所以第一个答案说PATH中的~符号会导致问题。但是我的$PATH是/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin。另一个答案说我需要将virtualenv安装路径放入我的PATH中。但是virtualenv在/usr/local/bin中 - 而且我的PATH,如上所述,确实有这个路径。第三个答案说python路径在不同的位置。所以我更改了bash_profile(现在在问题中)来指定python路径,但它给出了另一个错误。 - SKN
Python在Mac上已经准备就绪:which -a python /usr/local/bin/python /usr/bin/python 这是我在bash_profile中设置的VIRTUALENVWRAPPER_PYTHON,但是它会产生类似的错误。第四个答案说他通过easy_install安装了virtualenv,所以他必须通过pip重新安装。我不知道virtualenv是如何安装在我的机器上的(或者如何检查),但它位于/usr/local/bin,所以我使用sudo /usr/local/bin/pip uninstall virtualenv卸载了它,然后通过sudo /usr/local/bin/pip install virtualenv进行了安装,但没有帮助。 - SKN
上一个建议说他没有安装它,但是我已经安装了。还有其他建议吗? - SKN
3个回答

4

我也曾经对这个问题感到非常困惑。后来我通过卸载旧的stevedore并重新安装它来解决了这个问题。

sudo pip uninstall stevedore
sudo pip install stevedore

你真的需要 stevedore 还是它只是一个 罐头 - Timo
1
奇怪的是系统没有任何变化,但突然间这个东西停止工作了,直到重新安装它 :) - Juha Untinen

1
看起来您成功安装了virtualwrapper,但是缺少依赖项stevedore。请尝试安装它。
pip install stevedore

嗨,感谢您的回复(如果您收到了有关此评论编辑的通知,请原谅!)。看起来 stevedore 已经安装了,但是出现了一些警告(在 sudo pip 安装时)和错误(在 sudo -H pip 安装时)。也许这是一个权限问题?(我已经更新了我的主要问题,以便详细说明 pip 安装的情况,因为似乎通过评论格式化受限制)。谢谢! - SKN
好的,这很糟糕。您使用sudo [without -H]进行的安装尝试表明它已安装到用户中。它不能与sudo -H一起工作,这可能是MacOS的“特性”,可能的解决方法在这里:[https://dev59.com/llwY5IYBdhLWcg3waXEF#32661637]。我个人处理这个混乱的策略是在系统级别上安装必要的内容(在这种情况下是virtualenv、virtualwrapper),其他所有内容都在需要它的virtualenv中,并且不在用户级别上安装任何内容(不使用pip install --user)。 - hvwaldow
如果您想遵循该路径,请清除$HOME/Library/Python下的所有内容,获取适当的管理员权限,并为系统安装virtualwrapper(sudo -H pip install)。否则,您可能需要查看环境变量PYTHONPATH(https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH),以便找到为用户安装的模块。 - hvwaldow
所以我搜索了stevedore,然后得到了sudo find / -name stevedore /Users/sidharthnayyar/Library/Python/2.7/lib/python/site-packages/stevedore。这可能是问题所在吗?也就是说它不在/usr/local/bin中? - SKN
抱歉,我在发表评论后才看到您的消息。抱歉,我是Mac上的新手,但是当您说“清除”时,我想这只是删除的情况吧?还是我可以使用pip uninstall命令(/usr/local/bin/pip)?我检查了系统偏好设置,显然我的帐户是管理员 - 您是指像那个stackoverflow答案建议的那样执行“csrutil disable”吗?他们还说,除非您不是新手,否则不要这样做!..这让我很担心! :) - SKN
为了解决你的实际问题,我会执行“csrutil disable”命令,然后再执行“sudo -H pip install --upgrade --force-reinstall virtualenvwrapper”。我愿意冒这个险;)。之后你可以重新启用csrutil。是的,要想卸载用户安装的软件,“pip uninstall”应该可以解决(以用户身份执行,不要使用sudo)。 - hvwaldow

0
在Python 2.7下,使用sudo pip install stevedore。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接