25

On a fresh install of 16.04, I am trying to install virtualenvwrapper by following this great answer by Gerhard Burger.

after configuring the .bashrc, whenever opening the terminal displays

bash: /usr/local/bin/python2.7: No such file or directory
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/local/bin/python2.7 and that PATH is
set properly.

the script location is,

$ sudo find / -name virtualenvwrapper.sh
[sudo] password for john: 
/usr/local/bin/virtualenvwrapper.sh

contents of my .bashrc are,

export WORKON_HOME=/home/john/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=/home/john/.virtualenvs

here is my pip freeze

cffi==1.5.2
greenlet==0.4.9
pbr==1.10.0
readline==6.2.4.1
six==1.10.0
stevedore==1.15.0
virtualenv==15.0.2
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.1

the python interpreter's location,

$ which python
/usr/bin/python

How do I make it work?

thank you.

  • Welcome to AskUbuntu. You might want to include a link to said answer you refer to :) – Videonauth Jun 11 '16 at 07:46
  • @Videonauth Thanks. I just removed the link while cleaning up. sorry. – All Іѕ Vаиітy Jun 11 '16 at 07:49
  • @John My /usr/local/bin indeed doesn't contain python2.7, and I suspect yours doesn't either. which python2.7 says /usr/bin/python2.7, but I have not yet figured out how to tell virtualenvwrapper to look in /usr/bin instead of /usr/local/bin. – edwinksl Jun 11 '16 at 08:04
  • @John Based on http://virtualenvwrapper.readthedocs.io/en/latest/install.html#python-interpreter-virtualenv-and-path, can you add export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python to your .bashrc before source /usr/local/bin/virtualenvwrapper.sh? – edwinksl Jun 11 '16 at 08:18
  • 1
    @edwinksl tried it, but it doesn't fix. – All Іѕ Vаиітy Jun 11 '16 at 08:20
  • @John How about also adding export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv before source /usr/local/bin/virtualenvwrapper.sh? – edwinksl Jun 11 '16 at 08:27
  • @edwinksl sorry to say, that too doesn't work. – All Іѕ Vаиітy Jun 11 '16 at 08:30
  • @John Ah okay. I am not sure what to try next, so I will let others try instead. – edwinksl Jun 11 '16 at 08:37
  • I have the same problem, every time I open the terminal it displays

    `/usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (ImportError: 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. `

    – bit_scientist Mar 08 '17 at 03:37

5 Answers5

37

I am using Ubuntu server 16.04, You should also export the python interpreter in which you've installed the the virtualenvwrapper

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=~/.virtualenvs
source /home/vagrant/.local/bin/virtualenvwrapper.sh

Make sure to replace all the paths above according to your own system. Your wrapper script might e.g. be located in /usr/local/bin/virtualenvwrapper.sh instead, or you might use a different interpreter or virtualenvs home, ...

Byte Commander
  • 107,489
3

In the .bashrc change

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

and then make it work in the current shell by

source /usr/local/bin/virtualenvwrapper.sh 

Afterwards, change in the virtualenvwrapper.sh

VIRTUALENVWRAPPER_PYTHON="$(command \which python)"

to this

VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"
zx485
  • 2,426
Droopy
  • 31
  • 1
    VIRTUALENVWRAPPER_PYTHON="$(command \which python3)" worked for me. I think this was because I had two versions of python and it needed to know to pick python3 but it was installed in the homebrew. which python returned /usr/bin/python but which python3 returned /opt/homebrew/bin/python3 – Special Character Dec 06 '21 at 19:16
2

just comment

source /usr/local/bin/virtualenvwrapper.sh

line in

~/.bashrc

file....it worked for me.

1

You probably need to update your PYTHONPATH environment variable. In your .bashrc, before all the virtualenvwrapper variables, add the following line:

export PYTHONPATH=${PYTHONPATH}:/usr/bin
αғsнιη
  • 35,660
michael
  • 254
  • 1
  • 9
0

Firstly Cross-verify PATH in .bashrc with following commands:

which virtualenv

which virtualenvwrapper.sh

output of:

echo $VIRTUALENVWRAPPER_PYTHON

and

which python3

should be same which is

/usr/bin/python3

Configure the path accordingly to above results

export WORKON_HOME=~/.virtualenvs

export MY_PROJECT=~/my_proj

export VIRTUALENVWRAPPER_WORKON_CD=1

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

export VIRTUALENVWRAPPER_VIRTUALENV='result of which virtualenv'

source 'result of which virtualenvwrapper.sh'

if after verifying path still INITIALIZATION HOOK ERROR REMAINS.

Then, In source left everthing as it is just replace virtualenvwrapper.sh with virtualenvwrapper_lazy.sh

Then it should work