【问题标题】:Virtualenv: No module named virtualenvwrapper, path is wrongVirtualenv:没有名为 virtualenvwrapper 的模块,路径错误
【发布时间】:2014-02-17 19:50:21
【问题描述】:

为什么在安装 virtualenv 和 virtualenvwrapper 并添加之后

    export WORKON_HOME=$HOME/.virtualenvs
    export PROJECT_HOME=$HOME/Devel
    source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/virtualenvwrapper.sh

到我的.bash_profile 并运行$ source ~/.bash_profile,我遇到:

    /Library/Frameworks/Python.framework/Versions/7.3/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 virtualenv has been installed for
    VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/Current/bin/python and that PATH is set properly.

?

我的 .bash_profile 看起来像:

    # Setting PATH for EPD_free-7.3-2
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
    export PATH

    ##
    # Your previous /Users/<user>/.bash_profile file was backed up as /Users/<user>/.bash_profile.macports-saved_2012-11-06_at_11:39:22
    ##

    # MacPorts Installer addition on 2012-11-06_at_11:39:22: adding an appropriate PATH variable for use with MacPorts.
    export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    # Finished adapting your PATH environment variable for use with MacPorts.

    # virtualenvwrapper
    export WORKON_HOME=$HOME/.virtualenvs
    export PROJECT_HOME=$HOME/Devel
    source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/virtualenvwrapper.sh

    # Added by Canopy installer on 2014-01-26
    # VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
    VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/activate

【问题讨论】:

  • 您是否按字面意思输入了/Users/&lt;user&gt;。它应该替换为主目录的真实路径。

标签: macos python-2.7 virtualenv enthought virtualenvwrapper


【解决方案1】:

所以想通了。事实证明,当我为 python 安装 EPD 时,它添加了前几行:

    # Setting PATH for EPD_free-7.3-2
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
    export PATH

在我的.bash_profile。将我的 python 更新为 Enthought Canopy 后,我需要将这些行更改为:

   # set path for current python
   PATH="/Users/<user>/Library/Enthought/Canopy_64bit/User/bin:${PATH}"
   export PATH

现在一切正常。然而事实证明,这在一天结束时不会起作用,因为使用 Enthought,它向后移植了 venv,这是 here 所讨论的 python 3 标准。

【讨论】:

  • 仅供像我这样的其他人参考,通过 python.org 安装在 mac 上的 python 也会覆盖你的 .bash_profile,删除这些行也为我修复了它。
猜你喜欢
  • 2018-05-07
  • 2014-07-22
  • 2015-05-22
  • 2019-06-19
  • 1970-01-01
  • 2012-12-19
  • 2013-11-04
  • 2015-09-25
  • 2016-05-17
相关资源
最近更新 更多