[Solved] Virtualenvwrapper.sh error: There was a problem running the initialization hooks.

In the ubuntu environment, I made a soft link between python and python3.6 (ln -s python python3.6), and I made a soft link with pip, so after installing virtualenvwrapper with pip, start virtualenvwrapper at source. When sh and workon virtual environment always report an error:

1 ./virtualenvwrapper.sh: line 230: : command not found
2 virtualenvwrapper.sh: There was a problem running the initialization hooks.
4 If Python could not import the module virtualenvwrapper.hook_loader,
5 check that virtualenvwrapper has been installed for
7 set properly.

This is the statement on line 230 according to the hint:

1 "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' \

Combined with the error message and the sentence found in the prompt, it is guessed that there should be a problem with VIRTUALENVWRAPPER_PYTHON, and then look for VIRTUALENVWRAPPER_PYTHON in the virtualenvwrapper.sh file, and find the key points:

1 # Locate the global Python where virtualenvwrapper is installed.
 2  if [ " ${VIRTUALENVWRAPPER_PYTHON:-} " = "" ]
 3  then
 4      VIRTUALENVWRAPPER_PYTHON = " $(command \which python3) " # It was originally written \which python, here The one posted is after I modified it to python3. 
5 fi

VIRTUALENVWRAPPER_PYTHON is used (Locate the global Python where virtualenvwrapper is installed.) to locate which python has virtualenvwrapper installed. The location originally specified is python, which is version 2.7. Since I installed it using python3.6 before, I need to change it to python3 here. Then the error disappeared.

The advantage of using virtualenvwrapper is that you don’t need to use source /xxx/virtual environment/bin/activate every time to start the virtual environment. Configure it in ~/.bashrc. You can directly use the workon command to open the virtual environment in the future. The specific steps and premise You have installed python-virtualenv:

# Setup:
#  1. Create a directory to hold the virtual environments.
#     (mkdir $HOME/.virtualenvs).
#  2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
#     to your .bashrc.
#  3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
#     to your .bashrc.
#  4. Run: source ~/.bashrc
#  5. Run: workon
#  6. A list of environments, empty, is printed.
#  7. Run: mkvirtualenv temp
#  8. Run: workon
#  9. This time, the "temp" environment is included.
# 10. Run: workon temp
# 11. The virtual environment is activated.

Read More:

2 thoughts on “[Solved] Virtualenvwrapper.sh error: There was a problem running the initialization hooks.

Leave a Reply

Your email address will not be published. Required fields are marked *