mkvirtualenv: command not found
Solution 1
I added the following in my .bashrc, referring this
export PATH=/usr/local/bin:$PATH
source /usr/local/bin/virtualenvwrapper.sh
Now mkvirtualenv works-
pkoli@pkoli-SVE15136CNB:~/Desktop$ mkvirtualenv BUGS
Using base prefix '/usr'
New python executable in BUGS/bin/python3
Also creating executable in BUGS/bin/python
Installing setuptools, pip...done.
Solution 2
I ran into the same problem and I fixed it with by following the tutorial:
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
Part 1: Install the required packages
sudo apt-get install python-pip python-dev build-essential
sudo pip install virtualenv virtualenvwrapper
sudo pip install --upgrade pip
Part 2: Setup virtualenvwrapper in ~/.bashrc.
I used vim to edit ~/.bashrc.
Firstly, install vim with the command:
sudo apt-get install vim
Secondly, edit ~/.bashrc
vi .bashrc
enter [Shift] + [g] //G (shift + g): to go the end of the file
enter [a] //Type a to edit the file
Then insert three lines:
export WORKON_HOME=~/virtualenvs
export VIRTUALENVWRAPPER_PYTHON=[link-to-python-folder]
source /usr/local/bin/virtualenvwrapper.sh
where [link-to-python-folder]
can be, for example:
- if you are using python 3,
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3
- if you are using python 2,
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python
Next,
enter [Esc] then :wq
The Esc key means return the command line, :wq means save the changes and exit vi.
Part 3: Enable the virtual environment.
source ~/.bashrc
mkdir -p $WORKON_HOME
Now, you can try again with mkvirtualenv:
mkvirtualenv your_project
-
To enable the 'your_project' virtual environment:
workon your_project
-
To exit it:
deactivate
I noticed that when I installed separately virtualenv and virtualenvwrapper (with two times of 'sudo pip install'), I failed when run source ~/.bashrc
because of a failure of the importing the module virtualenvwrapper.hook_loader, so although you really installed virtualenv and virtualenvwrapper, let try it one more time with sudo pip install virtualenv virtualenvwrapper
.
Hope you find it useful!
aaragon
Updated on January 28, 2020Comments
-
aaragon over 4 years
I'm new to Python virtual environments, so after reading this tutorial I tried to create my first environment using
virtualenvwrapper
. My python3 installation is at the bare bones now:$ pip3 list argparse (1.2.1) pip (1.5.6) setuptools (2.1) stevedore (0.15) virtualenv (1.11.6) virtualenv-clone (0.2.5) virtualenvwrapper (4.3.1)
As suggested by the tutorial, I added the following lines to my .bashrc file:
export WORKON_HOME=$HOME/.virtualenvs source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh
which results in the following message when I open a new Terminal:
Last login: Wed Sep 10 22:33:17 on ttys006 -bash: _VIRTUALENVWRAPPER_API: unbound variable -bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable -bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable -bash: _VIRTUALENVWRAPPER_API: unbound variable -bash: _VIRTUALENVWRAPPER_API: unbound variable complete: usage: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]
I don't understand what the problem is, but clearly the
source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh
line fails because then I can't even find themkvirtualenv
command:$ mkvirtualenv test1 -p /usr/bin/python3.3 -bash: mkvirtualenv: command not found
I found this post and this one, with similar problems, but none of them gave me a solution.
-
Etan Reisner over 9 yearsWhat else is in your
.bashrc
file? -
aaragon over 9 yearsThere's a lot of stuff in my
.bashrc
file, the result of many years of work of adding different commands and functions from here and there. -
Etan Reisner over 9 yearsDo you
set -u
in there? -
aaragon over 9 yearsI do
set -o notify
,set -o noclobber
,set -o ignoreeof
,set -o nounset
. -
Etan Reisner over 9 yearsYeah,
set -o nounset
that'sset -u
. That's going to be the issue here. The preponderance of scripts out there aren't expecting to be run with that set as it makes many idiomatic actions fail. Disable that and see if it starts to work. -
aaragon over 9 yearsI now got
ERROR: virtualenvwrapper_lazy.sh: Could not find virtualenvwrapper.sh
, and I guess it's because thevirtualenvwrapper.sh
script is not on a default path? -
aaragon over 9 yearsThough it's recognizing the
mkvirtualenv
command now, but it doesn't seem to work:$ mkvirtualenv test1 -bash: : No such file or directory [Process completed]
. After I see that message[Process completed]
I can't do anything with the Terminal. -
Etan Reisner over 9 yearsThat message is your shell exiting (and your terminal telling you the session is dead), presumably because of something
mkvirtualenv
did (probably wrongly). ThePATH
idea looks like it might be right (if the file I'm looking at is the one you have). I don't know what might be going wrong withmkvirtualenv
specifically though. -
Etan Reisner over 9 yearsYou don't have
errexit
on do you? -
aaragon over 9 yearsI haven't set anything related to
errexit
in my.bashrc
file, just that when I open a new Terminal window I get the messageLast login: Wed Sep 10 23:25:04 on ttys000 ERROR: virtualenvwrapper_lazy.sh: Could not find virtualenvwrapper.sh
. -
Etan Reisner over 9 yearsAdjust your PATH so
which
can find that script and see if that fixes everything? -
aaragon over 9 yearsMy PATH variable seems to have that directory already, 3 times... =/ and I'm not even adding that path in the
.bashrc
file.$ echo $PATH /Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/aaragon/Local/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/texbin
. So I can dowhich virtualenvwrapper.sh
and it finds it. -
Etan Reisner over 9 yearsDoes it have it before you source
virtualenvwrapper_lazy.sh
? -
aaragon over 9 yearsIt was after, so I fixed that and now the command is working. Yet, I don't think I can create the environment yet:
$ mkvirtualenv --python=/usr/local/bin/python3 pydev Running virtualenv with interpreter /usr/local/bin/python3 Using base prefix '/Library/Frameworks/Python.framework/Versions/3.4' New python executable in pydev/bin/python3 Also creating executable in pydev/bin/python Installing setuptools, pip...done. /usr/bin/python: No module named virtualenvwrapper
-
aaragon over 9 yearsThat error shows up when I try to
workon
the environment:$ workon pydev /usr/bin/python: No module named virtualenvwrapper /usr/bin/python: No module named virtualenvwrapper
. Well, I haven't installedvirtualenvwrapper
withpython
but only inpython3
. -
Etan Reisner over 9 yearsDoes setting
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
fix that problem? I should point out that I am gathering all of this from looking at the scripts in question. I should also say that clearly something is wrong with either your setup orvirtualenv
itself if this much fiddling is required. It might make sense to find people who actually know/work withvirtualenv
to see what they make of all this. -
aaragon over 9 yearsAfter setting that environmental variable things get even worst because now when I type
workon pydev
I get again a[Process completed]
message and the Terminal doesn't work anymore. -
Etan Reisner over 9 yearsLike I said before
[Process completed]
means the shell that was being run in that window exited (in some way that didn't trigger the window to close, so perhaps an unclean exit). Also like I said, I think something is not quite right either with your system or withvirtualenv
itself but I'm not able to assess thevirtualenv
side of things and digging deeper into your system setup is an involved process. Sorry. -
aaragon over 9 yearsI was finally able to make it work. I took my
.bashrc
file and I cleaned, removed everything I didn't need. Now it works fine, but I still think the process of makingvirtualenvwrapper
work is painful, as you have to add stuff to your profile file. -
Etan Reisner over 9 yearsI will point out that there is a reason I asked what was in it at the start of all of this. =) I'm curious, if you are willing to share, what all you removed that might have been able to cause these myriad problems.
-
aaragon over 9 yearsWell, I went to this website, and I took many things from there, which I mixed with my old
.bashrc
. I spent the entire morning doing that, in the end, I triedvirtualenvwrapper
and it was working already, but I really don't know what fixed it. I could send you both versions of the.bashrc
file if you want. -
Etan Reisner over 9 yearsNothing in there looks overly harmful though the
cd
function andwhich
alias could certainly cause some things problems. -
aaragon over 9 yearsI recall the
which
function being called within thevirtualenvwrapper_lazy.sh
. But I don't think this was the problem because I still have that alias, and it now works.
-
-
caprica almost 9 yearsFor my Kubuntu it was installed here: /usr/share/virtualenvwrapper/virtualenvwrapper.sh
-
Feiteira almost 5 yearsNote that on step 2, I needed to add an extra line:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3