【问题标题】:Error message for virtualenvwrapper installed with homebrew on Mac Sierra在 Mac Sierra 上随 homebrew 安装的 virtualenvwrapper 的错误消息
【发布时间】:2017-09-27 04:43:26
【问题描述】:

我使用自制软件安装了 virtualenv 和 virtualenvwrapper,但是当我尝试 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.

我的 .bash_profile 如下所示:

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

我有一台运行 Sierra (10.12.4) 的 mac。

任何帮助表示赞赏!

【问题讨论】:

    标签: python virtualenv homebrew macos-sierra virtualenvwrapper


    【解决方案1】:

    我已经通过自制软件安装了 macOS 10.12.6 和 python 2。

    对我有用的是通过添加export PATH="/usr/local/opt/python/libexec/bin:$PATH" 来确保自制python 在$PATH 环境变量中的系统python 前面。

    我的.zshrc 的相关部分如下所示:

    ## 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
    

    我从公式文档中得到了这个想法:

    » 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"
    # (...)
    

    我怀疑 bash 是一样的。

    【讨论】:

      【解决方案2】:

      如果以后有人觉得这很有帮助,对我有用的是安装 conda 而不是 virtualenv。

      无论出于何种原因,安装 conda 后,virtualenv 也开始工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-27
        • 2015-06-26
        • 2017-04-05
        • 2018-05-03
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        相关资源
        最近更新 更多