Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Virtualenv-没有名为VirtualEnvRapper.hook_loader的模块_Python_Virtualenv_Virtualenvwrapper - Fatal编程技术网

Python Virtualenv-没有名为VirtualEnvRapper.hook_loader的模块

Python Virtualenv-没有名为VirtualEnvRapper.hook_loader的模块,python,virtualenv,virtualenvwrapper,Python,Virtualenv,Virtualenvwrapper,我正在运行MacOS10.6.8。除了python 2.6之外,还想安装python 2.7,并在新的virtualenv中使用python 2.7。我执行了以下步骤: 我下载了python 2.7并安装了它: http://www.python.org/ftp/python/2.7.3/python-2.7.3-macosx10.6.dmg 然后,我运行命令,使用python2.7设置一个新的virtualenv: mkvirtualenv --python=python2.7 mynewe

我正在运行MacOS10.6.8。除了python 2.6之外,还想安装python 2.7,并在新的virtualenv中使用python 2.7。我执行了以下步骤:

我下载了python 2.7并安装了它:

http://www.python.org/ftp/python/2.7.3/python-2.7.3-macosx10.6.dmg
然后,我运行命令,使用python2.7设置一个新的virtualenv:

mkvirtualenv --python=python2.7 mynewenv
我的.bash_配置文件如下所示:

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


# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
$  ~/ -name virtualenvwrapper.sh # to see where you have this. May already be prefilled in your shell profile[.zshrc or .profile]

$ which python   # to know the default python your project or rather where conda has installed python for you
现在,当我打开控制台时,我得到以下错误消息

ImportError: No module named virtualenvwrapper.hook_loader
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=/usr/local/bin/python and that PATH is set properly.
我还在另一篇帖子中发现,我应该升级VirtualVWrapper。这没有帮助

sudo pip install virtualenvwrapper --upgrade

如有任何帮助,我们将不胜感激。

问题已通过以下步骤解决:

#switch the /usr/bin/python link to point to current python link
cd /usr/bin
sudo mv python python.bak
sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python python
重新排列export命令,使其位于my.bash_概要文件中的virtualenv命令之前:

PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
export PATH

# needed for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
重新安装setuptools,轻松安装和PIP。这显然是必要的,以便它们能够在新的python版本中正常工作:

sudo sh setuptools-0.6c11-py2.7.egg

sudo easy_install-2.7 pip

pip install virtualenv

另外,如果您有macports,请确保路径中的
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
列在
/Library/Frameworks/Python.framework/Versions/2.7/bin
之前。然后在
.profile
中设置以下内容:

export VIRTUALENVWRAPPER_PYTHON=`which python`
export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`
source `which virtualenvwrapper.sh`

这发生在我身上,我通过重新安装
pip
解决了这个问题。结果是,
哪个pip
给出了
/usr/bin/pip
,而
哪个python
给出了
/usr/local/bin/python
pip
的路径应该是
/usr/local/bin/pip
。当我更新我的Python安装时,这可能会中断

如果您可以轻松地为当前工作的Python设置重新安装
pip
。您需要:

  • 下载脚本(直接从
    pip
    的文档链接)
  • 运行
    python获取pip.py

  • 这为我解决了问题。

    我刚刚安装了python 3.5,尝试了VirtualNVRapper,然后出现了这个问题。我开始意识到python3.5安装在
    /usr/local/bin/python3.5
    中,而不是
    /usr/bin/python3.5
    。因此,我修改了我的.bash_配置文件脚本,使其看起来像下面的脚本,现在一切似乎都正常了

    # Setting PATH for Python 3.5
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
    export PATH
    export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.5
    export WORKON_HOME=$HOME/.virtualenvs
    source /Users/bentaub/.virtualenvs/djangodev/bin/virtualenvwrapper.sh
    

    作为一个新手,我不确定python3.5路径中的“本地”从长远来看会对我产生什么影响,但就目前而言,它是有效的。

    有很多因素会导致这个错误。如果您的环境是

    • CentOS 7,配有
      python3
      安装于
      epel版本
    • pip3
      安装了
      python3.4 get pip.py
    • virtualenvwrapper
      pip3一起安装
    • mkvirtualenv-p/usr/bin/python3.4创建的python虚拟环境
    然后,无论出于何种原因,创建虚拟环境时都没有VirtualNVRapper库。您只需再次安装即可解决此问题,但这次是从virtlualenv内部安装

    [user@localhost ~] $ mkvirtualenv -p /usr/bin/python3.4 venv
    Using base prefix '/usr'
    New python executable in /home/user/.virtualenvs/venv/bin/python3.4
    Also creating executable in /home/user/.virtualenvs/venv/bin/python
    Installing setuptools, pip, wheel...done.
    virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/predeactivate
    virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/postdeactivate
    virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/preactivate
    virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/postactivate
    virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/get_env_details
    /home/user/.virtualenvs/venv/bin/python3.4: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
    /home/user/.virtualenvs/venv/bin/python3.4: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
    
    # the virtualenv should now activated
    (venv)[user@localhost ~] $ pip install virtualenvwrapper
    
    [user@localhost~]$mkvirtualenv-p/usr/bin/python3.4 venv
    使用基本前缀“/usr”
    /home/user/.virtualenvs/venv/bin/python3.4中新的python可执行文件
    还在/home/user/.virtualenvs/venv/bin/python中创建可执行文件
    安装setuptools、pip、wheel…完成。
    virtualenvwrapper.user\u脚本创建/home/user/.virtualenvs/venv/bin/predeactivate
    virtualenvwrapper.user\u脚本创建/home/user/.virtualenvs/venv/bin/postdeactivate
    virtualenvwrapper.user\u脚本创建/home/user/.virtualenvs/venv/bin/preactivate
    virtualenvwrapper.user\u脚本创建/home/user/.virtualenvs/venv/bin/postactivate
    virtualenvwrapper.user\u脚本创建/home/user/.virtualenvs/venv/bin/get\u env\u详细信息
    /home/user/.virtualenvs/venv/bin/python3.4:查找“virtualenvwrapper.hook\u loader”的规范时出错(:没有名为“virtualenvwrapper”的模块)
    /home/user/.virtualenvs/venv/bin/python3.4:查找“virtualenvwrapper.hook\u loader”的规范时出错(:没有名为“virtualenvwrapper”的模块)
    #现在应该激活virtualenv
    (venv)[user@localhost~]$pip安装VirtualEnvrapper
    
    我在卸载
    virtualenvwrapper
    软件包后遇到了这个问题。当我登录到任何用户(或
    su
    登录到其他用户)时,我会得到:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named virtualenvwrapper.hook_loader                                                                                                                                                                       
    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=/usr/bin/python and that PATH is                                                                                                                                                                        
    set properly.
    

    我也犯了同样的错误。发现我有旧版本的皮普。我通过升级pip修复了这个错误。

    尝试卸载您的
    virtualenv
    virtualenvwrapper
    ,然后使用2.7版中的
    pip
    再次安装它(我想)

    我遇到了同样的错误,我只是这样做,解决了我的问题


    在我的例子中,我使用U

    ,将这一行添加到我的.zshrc文件中,成功了

    export VIRTUALENVWRAPPER_PYTHON=/usr/local/Cellar/python/2.7.13/bin/python2.7
    

    我只需要确保/usr/local/bin/python存在

    对我来说,这很简单:

    ln -s /usr/local/bin/python2.7 /usr/local/bin/python
    

    即使有一个公认的答案,我想我会把它给我

    首先,我安装了Python,刚刚通过自制升级了它。我也在使用ZSH,所以如果某些位与您的输出不太匹配,那可能就是原因

    通过运行brew info python并查看输出,我发现了以下信息:

    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"
    
    因此,我将其添加到终端启动脚本中,如图所示,错误n不再显示


    注意:我将其插入路径的另一部分,错误在启动时仍然存在。

    在安装Conda/Anaconda项目后遇到类似问题。这个问题对解决我在MAC上的问题很有帮助。解决这个问题使我的
    .zshrc
    相关部分如下所示:

    export VIRTUALENVWRAPPER_PYTHON=$HOME/Applications/conda/bin/python
    source $HOME/Applications/conda/bin/virtualenvwrapper.sh
    
    这取决于我在哪里安装了conda,您必须在您自己的案例中进行计算。要根据安装anaconda的位置获取给定环境的详细信息,可以使用以下方法:

    # needed for 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
    
    
    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH
    
    $  ~/ -name virtualenvwrapper.sh # to see where you have this. May already be prefilled in your shell profile[.zshrc or .profile]
    
    $ which python   # to know the default python your project or rather where conda has installed python for you
    

    别忘了卸载和安装virtualenv和VirtualEnvRapper,如其他答案中突出显示的那样。

    刚刚在Centos 7.4上遇到了这个问题

    which python3 # outputs /usr/bin/python3 
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3  
    source `which virtualenvwrapper.sh`  
    
    python3
    
    import sys;print('\n'.join(sys.path))
    
    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages