Program Club

Python Virtualenv-virtualenvwrapper.hook_loader라는 모듈이 없습니다.

proclub 2020. 10. 19. 13:03
반응형

Python Virtualenv-virtualenvwrapper.hook_loader라는 모듈이 없습니다.


Mac OS 10.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_profile은 다음과 같습니다.

# 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

이제 콘솔을 열면 다음과 같은 오류 메시지가 나타납니다.

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.

다른 게시물에서도 virtualenvwrapper를 업그레이드해야한다는 사실을 발견했습니다. 도움이되지 않았습니다.

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

내 .bash_profile 파일에서 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를 다시 설치하십시오. 이것은 새로운 파이썬 버전에서 제대로 작동하기 위해 분명히 필요합니다.

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

sudo easy_install-2.7 pip

pip install virtualenv

또한 macport /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin있는 경우 PATH /Library/Frameworks/Python.framework/Versions/2.7/bin목록 에이 있는지 확인하십시오 /usr/local/bin. 그런 다음 다음을 설정하십시오 .profile.

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

제 경우에는이 줄을 .zshrc 파일에 추가하는 것이 트릭이었습니다.

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

이것은 나에게 일어 났고 .NET을 다시 설치하여 해결했습니다 pip. 앞으로 일어날 그했다 있었다 무엇 which pip/usr/bin/pip결과로, 동안을 which python했다 /usr/local/bin/python. 의 경로는 pip이어야합니다 /usr/local/bin/pip. 이것은 Python 설치를 업데이트했을 때 깨졌을 것입니다.

당신이 경우 핍 문서에 따라 쉽게 재설치 할 수를 pip현재 작업 파이썬 설치에. 다음을 수행해야합니다.

  1. get-pip.py 스크립트를 다운로드합니다 ( pip의 문서 에서 직접 링크 됨 ).
  2. 을 실행 python get-pip.py합니다.

이것은 나를 위해 문제를 해결했습니다.


Ubuntu 18.04Python 3+를 사용하는 모든 사람에게 이것은 나를 위해 트릭을 수행했습니다.

which python3 # outputs /usr/bin/python3 
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3  
source `which virtualenvwrapper.sh`  

이 오류를 일으킬 수있는 여러 가지가 있습니다. 환경이

  • CentOS 7, 다음에서 python3설치epel-release
  • pip3 함께 설치 python3.4 get-pip.py
  • virtualenvwrapper 함께 설치 pip3
  • 다음으로 만든 Python 가상 환경 mkvirtualenv -p /usr/bin/python3.4

그런 다음 어떤 이유로 든 virtualenvwrapper 라이브러리없이 가상 환경이 생성됩니다. 간단히 다시 설치하여 해결할 수 있지만 이번에는 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

/ usr / local / bin / python이 존재하는지 확인해야했습니다.

저에게는 간단했습니다.

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

같은 오류가 발생합니다. 이전 버전의 pip가 있다는 것을 알았습니다. 간단히 pip를 업그레이드하여 오류를 수정했습니다.


I just installed python 3.5,tried the virtualenvwrapper and then had this problem. I came to realize that python3.5 was installed in /usr/local/bin/python3.5 and NOT /usr/bin/python3.5. So, I revised my .bash_profile script to look like the following and everything seems to work now

# 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

I'm enough of a novice to not be sure how that 'local' in the path to python3.5 is going to affect me in the long run but, for now, it works.


I had this problem after uninstalling the virtualenvwrapper package. When I logged in to any user (or su to a different one), I would get:

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.

The solution was to delete the /etc/bash_completion.d/virtualenvwrapper file.

Edit:

Do not delete the above file or it won't be recreated if you reinstall virtualenvwrapper. Instead what you need to do is purge the virtualenvwrapper package when you uninstall it. Like this on Debian:

apt-get remove --purge virtualenvwrapper

Try to uninstall your virtualenv and virtualenvwrapper and install it again using pip in version 2.7 (I think).

I encountered the same error and I just did this and solved my problem.

I using U


Even though there is an accepted answer I thought I would put what fixed it for me.

Firstly I installed Python and had just upgraded it via Homebrew. I am also using ZSH so if some bits don't quite match your output then that might be why.

By running brew info python and looking through the output I found the following nice bit of information:

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"

So I added this to my terminal startup script as shown and the error n longer displays.

Note: I inserted this into another part of my PATH and the error persisted on start up.


Ran into a similar issue after installing Conda/Anaconda project. This question was quite helpful in resolving my issue on MAC.Resolving the issue had my .zshrc relevant portion looking like this:

export VIRTUALENVWRAPPER_PYTHON=$HOME/Applications/conda/bin/python
source $HOME/Applications/conda/bin/virtualenvwrapper.sh

This is depended on where I have conda installed and you'll have to figure that in your own case. To get the specifics for your given environment depending on where you've installed anaconda you can use the following:

$  ~/ -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

DON'T FORGET TO UNINSTALL AND INSTALL virtualenv and virtualenvwrapper as highlighted in other answers.


Just bumped into this issue on a Centos 7.4.

None of the above answers suited my case. After quite a bit of digging around I pinpointed this to too-strict file permissions in python libs (I guess python installation on Centos differs a bit from other POSIX systems).

So, if everything else fails you might want to check that your python libs are readable by the user you're trying to run virtualenvwrapper with.

In particular check: /usr/lib/python3.6 /usr/lib64/python3.6 (amend the paths for different python versions).

If you see that group and others lack read and execute permissions in there then add them: sudo chmod og+rx -R /usr/lib/python3.6 sudo chmod og+rx -R /usr/lib64/python3.6

Note: I'm not sure whether this works against a Centos security policy but it's probably safe as long as you don't give write persmisions.


In my situation (OS X 10.13.6), this did it

brew install python2 --upgrade

I had the same problem as this one and spent so much time on configuring out what was wrong. And I finally found out what was wrong.

First I looked for where virtualenvwrapper folder exists. In my case /usr/local/lib/python3.7/site-packages. Inside the folder is hook_loader.py that caused the error.

Next, I used python script.

python3

import sys;print('\n'.join(sys.path))

I couldn't find the /usr/local/lib/python3.7/site-packages directory so, at last I wrote,

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages

to .bashrc file. Done.

Meaning of PYTHON PATH

As you can see in above link, PYTHONPATH augment the default search path for modules.

참고URL : https://stackoverflow.com/questions/11507186/python-virtualenv-no-module-named-virtualenvwrapper-hook-loader

반응형