Virtualenvwrapper_run_hook:12: permission denied error when running Environment

4.4k Views Asked by At

I've installed Virtualenvwrapper, and it seems to be running fine, but anytime I activate an env or run workon venv I get the following:

virtualenvwrapper_run_hook:12: permission denied: 
virtualenvwrapper_run_hook:12: permission denied:

This is what my .bash_profile looks like

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh

Here are my packages

Package           Version
----------------- -------
distlib           0.3.4
filelock          3.7.0
pbr               5.9.0
pip               22.1.1
platformdirs      2.5.2
setuptools        49.2.1
six               1.15.0
stevedore         3.5.0
virtualenv        20.14.1
virtualenv-clone  0.5.7
virtualenvwrapper 4.8.4
wheel             0.36.2

I am using Python3.8.9

It looks like my environment activated, but I'm not a fan of seeing an error message I don't understand.

3

There are 3 best solutions below

0
Jesse On

I used vi ~/.zshrc to open my .zshrc file. Then I changed it to the following:

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /Users/username/.local/bin/virtualenvwrapper.sh

Replacing username with my actual user name.

I ran:

source ~/.zshrc

and it now all works. I think this is because for mac terminal I needed to edit my .zshrc file. I also downloaded the virtualenvwrapper package with pipx initially.

1
juanesarango On

In my case, I used homebrew to install python3 in my Apple M2. Where the script for virtualenwrapper is located at: /opt/homebrew/bin/virtualenvwrapper.sh.

Additionally, I don't have python linked, but python3 instead. As virtualenvwrapper will look for the python executable using command which python I was getting the error:

virtualenvwrapper_run_hook:12: permission denied:
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= and that PATH is
set properly.

Adding then VIRTUALENVWRAPPER_PYTHON whith the python3 path fixed my issue. This is how my profile looks like:

# Virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/opt/homebrew/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /opt/homebrew/bin/virtualenvwrapper.sh
0
Eugene M. On

I concur with the answers above.
Solution: Add the following line export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 to the .zshrc config file. Running source ~/.zshrc to reload the file and apply the changes run successfully without the prior error:

virtualenvwrapper_run_hook:12: permission denied:
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= and that PATH is
set properly.

Oddly enough, that line of code was not included in the virtualenvwrapper installation docs.

Other information:

  • NB: If you alternate between different Python versions on your machine (ie. sudo update-alternatives --config python3), you may encounter the following error when launching the terminal with a Python version different from the one used to install virtualenvwrapper:
/usr/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: 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 virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is
set properly.
  • My current virtualenvwrapper config in my .zshrc file:
# virtualenvwrapper configuration
#
## Set the following:
### - path for installing py interpreter
### - where the virtual envs should live
### - path for development project dirs
### - path for virtualenv installation
### - path of the package's installed script
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/.local/bin/virtualenv

source $HOME/.local/bin/virtualenvwrapper.sh

Context: OS: Ubuntu Focal LTS (20.04.6) Interpreter: Python 3.8.10