Error message for virtualenvwrapper installed with homebrew on Mac Sierra

狂风中的少年 提交于 2019-12-23 04:19:35

问题


I installed virtualenv and virtualenvwrapper using homebrew, but am getting the following error when I try source virtualenvwrapper.sh

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, 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/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
    from stevedore import ExtensionManager
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/stevedore/__init__.py", line 11, in <module>
    from .extension import ExtensionManager
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/stevedore/extension.py", line 17, in <module>
    import pkg_resources
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 72, in <module>
    import packaging.requirements
  File "/Library/Python/2.7/site-packages/packaging/requirements.py", line 59, in <module>
    MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)
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.

My .bash_profile looks like this:

export PATH=/usr/local/bin:$PATH
# virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

I have a mac running Sierra (10.12.4).

Any help appreciated!


回答1:


In case anyone in the future finds this helpful, what worked for me was to install conda instead of virtualenv.

For whatever reason after installing conda, virtualenv started working too.




回答2:


I've got macOS 10.12.6 and python 2 installed via homebrew.

What worked for me was to make sure that homebrew python is in front of the system python in $PATH env variable by adding export PATH="/usr/local/opt/python/libexec/bin:$PATH".

The relevant part of my .zshrc looks like this:

## Python
export PATH="/usr/local/opt/python/libexec/bin:$PATH"  # homebrew python 2 in front of the system one
export WORKON_HOME="$HOME/Virtualenvs"
source /usr/local/bin/virtualenvwrapper.sh

I've got this idea from the formula documentation:

» brew info python
python: stable 2.7.13 (bottled), HEAD
# (...)
==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.zshrc:
  export PATH="/usr/local/opt/python/libexec/bin:$PATH"
# (...)

I suspect for bash it is the same.



来源:https://stackoverflow.com/questions/43690784/error-message-for-virtualenvwrapper-installed-with-homebrew-on-mac-sierra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!