1

I am using Python3.7 and following the virtualenv and virtualenvwrapper installation as mentioned on this FreeCodeCamp article.

The changes to my .bashrc file look as follows:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# popo edit: Add Python alias
alias python=python3

# popo edit: Step to activate virtualenvs
export WORKON_HOME=$HOME/.virtualenvs

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
# SOme more things....

#Virtualenvwrapper settings:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/pra-dan/.local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

On sourcing the .bashrc, I get

/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.

ALthough, I managed to make an environment (idk how) and on typing workon, I get its name.

But now when I wish to make a new environment, I enter $ mkvirtualenv wrk -p python3, I get

ERROR: virtualenvwrapper could not find /home/pra-dan/.local/bin/virtualenv in your path

4 Answers 4

1

On Ubuntu 18.04, I have had the following:

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.

sudo gedit .bashrc

It is how virtualenvwrapper settings in .bashrc look like in my case:

export WORKON_HOME=~/.envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh

And I have done the following:

sudo apt install python3-pip
sudo pip3 install virtualenv virtualenvwrapper
source ~/.bashrc

That has helped me.

0

I think you missed an important note in the instructions: the export lines need to come before sourcing virtualenvwrapper.sh. You're sourcing virtualenvwrapper.sh twice.

3
  • It doesn't work @brian
    – Pe Dro
    Aug 28, 2020 at 12:32
  • Edited my answer, you need the exports before the sourcing of virtualenvwrapper.sh per the instructions. Aug 28, 2020 at 12:37
  • I corrected my .bashrc and the above question but still have the problem after sourcing it
    – Pe Dro
    Aug 28, 2020 at 12:46
0

Confirm that the python path provided in

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

is same as the python path where you installed virtualenv and virtualenvwrapper.

To find your python path, use which python or, which python3 command in console.

Also verify that either python or python3 command in terminal triggers a python IDLE of the desired version.

0

On Ubuntu 20.04 focal which python yields nothing, whereas which python3 does. However /usr/local/bin/virtualenvwrapper.sh relies on which python:

# Locate the global Python where virtualenvwrapper is installed.
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

So you may edit the latter file with sudo and change which python to which python3 or add an export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 (or any value shown by which python3) at the top of your home's .bashrc file.

Then to install virtualenvwrapper (for current user), run:

sudo apt-get install python3-pip
pip install virtualenvwrapper

Create a new terminal or log out/log in again to ensure the message has disappeared.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .