I have installed python2 and python3 in my Mac osx and currently I'm using python3. And I am able to pip3 install virtualenv and virtualenvwrapper. The problem is whenever I restart my terminal, the settings for virtualenvwrapper don't work, like I can't use the commands mkvirtualenv and workon. The error I get is bash: the command workon is not found. I think there must be something wrong with my settings about the virtualenvwrapper. Here is what I try:
edit the ~/.bashrc:
export WORKON_HOME=~/Envs
source ~/Envs/django_projects/bin/virtualenvwrapper.sh
All my virtualenv packages are installed in the ~/Envs and after that, I source the .bashrc and it works, I could use workon and mkvirtualenv but once I reopen a new terminal it still could find't the workon command.
Does anyone know what's wrong with my setting?
After a few try, finally it works. There are two problems. The first one is because I have both python2 and python3 installed in my machine and by default the virtualenvwrapper try to run using the default python(in /usr/bin/python which is python2) so I have to change it to point to python3. So in my .bashrc file:
export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_PYTHON=PATHS/TO/PYTHON3
source ~/Envs/django_projects/bin/virtualenvwrapper.sh
The second one is that .bashrc doesn't run automatically,we have to source in to ./bash_profile. Check https://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically for detail.
Then reopen the terminal and ta-da.
In order to be able to use virtualenvwrapper you need to source the script that is somewhere in /Users/mic4ael/Library/Python/{Python version}/bin/virtualenvwrapper.sh. So you could put source /Users/mic4ael/Library/Python/{Python version}/bin/virtualenvwrapper.sh to your .bashrc to make it every time you launch a terminal.
Related
I created a virtual environment in my new directory with virtualenv env and then in Windows Git Bash ran env/Scripts/activate, which seemed to work. I didn't notice my virtualenv being displayed in parens at the beginning of the line (question1: can I set it up to work like that?), so to check if it was indeed activated I ran pip -V which gave me:
pip 9.0.1 from c:\tools\python2\lib\site-packages (python 2.7)
Shouldn't that be giving the directory of my virtualenv rather than site-packages? I also ran pip list and it gave me a list of installs that I had (naughtily) installed globally for a different project. So I can only assume my virtualenv did not activate and I don't know why that is.
Your suspicions are correct. Try source Scripts/activate. What you did will run the command in a new and temporary shell instance.
I am trying to run virtualenv for the first time and when I run the following code the shell prompt does not change.
$ virtualenv test
New python executable in test/bin/python
Installing setuptools............done.
$ source test/bin/activate
$
I'm assuming it did not activate my environment because there is no (test)$ prompt. The virtualenv command creates the directory correctly, so the activate file is there, it just seems to not be working?
I have tried this command as well and it gives the same result.
$ . test/bin/activate
$
Is my virtual environment running and I just cannot see the prompt(and is there something I can run to check that)?
or
Is my virtual environment simply not running and I am not activating it correctly?
I'm using Python 3.6.0(installed from Homebrew), virtualenv 15.1.0, Mac OS X 10.11.6, and zsh(oh-my-zsh)
To tell if your virtualenv is active without depending on the prompt (which shell configuration can override in persistent ways), use:
declare -p VIRTUAL_ENV
If the output is:
declare: no such variable: VIRTUAL_ENV
...then your virtualenv is genuinely not active. By contrast, if the output is:
typeset -x VIRTUAL_ENV=/Users/jess/test
...then it's active, but your prompt has been overridden.
To diagnose this (either the failure to activate, or the prompt override not sticking) in zsh, use:
PS4=':%x:%I+' # the equivalent to this in bash would be PS4=':$BASH_SOURCE:$LINENO+'
set -x
source test/bin/activate
...which will print source file, line number, and command executed for everything done both during and after the activate script is sourced; this should include the activate script updating your PS1 (or, potentially deciding for some reason not to execute); and may include a function hook changing your PS1 back to a version that doesn't have the prompt updated to show the virtualenv's state.
Thanks to the help from Charles, I discovered it was my oh-my-zsh theme(powerlevel9k) that was just not displaying the prompt. I simply needed to add in the virtualenv Python Segment in my ~/.zshrc described here.
If you are using oh-my-zsh on iterm and want to prompt virtual environment then ,
Do open ~/.zshrc Add/update virtualenv in that file like this POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) Then finaly don't lforget to source ~/.zshrc
I installed virtualenv using the command sudo pip install virtualenv and the installation is successful. Later, when I type virtualenv, I get the error message as following, -bash: virtualenv: command not found
The virtualenv is installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. I see the similar questions in the forum with no definitive answers.
Python is in the location /usr/local/bin/python and I have version 2.7.9. I get the following using ls -l command,
Why do I see the virtualenv is not found and how to solve the issue ?
UPDATE:
I use the command
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py to put the virtualenv.py
inside the /usr/local/bin folder. Previously, I only did the same for the virtualenv file. Now, when I put the command virtualenv in the terminal, I get
-bash: /usr/local/bin/virtualenv: Permission denied.
I later use
sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py
and the say message keep showing. which virtualenv still returns nothing.
Pursuant to #Jason's suggestion, try making the symbolic link for virtualenv in the /bin directory like so:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv /usr/local/bin/virtualenv
Why don't re-install virtualenv? Also try to use the latest version of pip (sudo pip install -U pip).
Not sure if the answer will be useful to you, as i see the question is a few month old, but maybe it will be helpful for others.
I encountered the same problem, after installing python3.5 and pyCharm on my Mac. I moved the 3.5 folder from /Library/Frameworks/Python.framework/Versions/3.5 to /System/Library/Frameworks/Python.framework/Versions/3.5, following this guide, after disabling the System Integrity Protection first with reboot into recovery mode (boot with ctrl+R), and executing csrutil disable in the terminal. After reboot it was possible to move the python3.5 folder, and then i followed the guide, and everything worked like charm. In pyCharm i could choose the version 3.5 from /System/... instead of /Library/... (however, i still left a soft link in /Library/... to the /System folder where the python3.5 now was, just in case), and after adding the path to my zsh i could execute pip3 install virtualenv. So far so good.
Next, i tried to create the environment with virtualenv -p python3 env, and here i had the same problem as you. It seemed like the path could not be added somehow. Initially i also tried to look in the /System/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ and include it in the $PATH, then also create softlinks to virtualenv.py as you tried too, but finally found that although all the files are in the site-packages folder, the actual executable was in /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv. As the path there was included in my $PATH, i have no idea why it did not execute when typing virtualenv -p python3 env, even with sudo as you tried too, but once i typed the full path /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv -p python3 env, it worked like charm again.
I still have no idea why, but it worked and now i can move on :)
Hope it helps, and hope someone can explain this better than me.
You are created the symbolic link to the wrong file. As far as I know virtualenv is installed to /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv, (you can change the numbers for your Python version) so the command for creating the symbolic link should be:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
I'm trying to create a virtualenv with virtualenvwrapper, but when I use mkvirtualenv I get the following :
ERROR: virtualenvwrapper could not find virtualenv in your path
I assumed it was a PYTHONPATH problem.
But if I do a pip show virtualenv I get the following :
---
Metadata-Version: 2.0
Name: virtualenv
Version: 13.1.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Jannis Leidel, Carl Meyer and Brian Rosner
Author-email: python-virtualenv#groups.google.com
License: MIT
Location: /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages
Requires:
And here is my PYTHONPATH :
/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:~/.brew/Cellar
It contains the directory containing virtualenv!
(i-e : /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages )
My ~/.zshrc contains :
export WORKON_HOME=~/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME"/Library/Python/2.7/bin/virtualenvwrapper.sh"
EDIT :
virtualenvwrapper.sh is written in bash, perhaps should I check my PATH instead of my PYTHONPATH ?
So, what could the problem be? How could I fix it?
Thank you in advance for your help.
Re-installling virtualenv fixed my problem.
I had the same issue.
$ mkvirtualenv mysite
ERROR: virtualenvwrapper could not find virtualenv in your path
After a lot of time consuming efforts,
I decided to re-install virtualenv.
sudo apt install virtualenv
This fixed my issues.
I already had virtualenv installed. But I think it got broken or met with some errors.
I am using python3 with virtualenvwrapper installed on Ubuntu 18.04, using pip3 without sudo. If you are in this situation, you might find interesting my configuration.
In the end of my .bashrc I added the following rows (remember to put your username in the YOUR_USERNAME field):
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/YOUR_USERNAME/.local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Then restart the cli with ctrl-D ctrl-T or reload the config with source ~/.bashrc.
Then you should be good to go! Try the installation with:
lsvirtualenv
mkvirtualenv test
workon test
deactivate
rmvirtualenv test
If you could create and delete a virtual environment, you are ready to go.
sudo find / -name "virtualenv"
Then I find the executable file path is:
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
Touch a soft link in the /usr/local/bin/ directory or add the path to .bash_profile, I prefer the former:
sudo ln -s /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
I finally found out what the problem was :
virtualenvwrapper.sh is written in BASH and not in Python.
So virtualenv is called from a shell (zsh).
I didn't have to bother about my PYTHONPATH, but about my PATH (I was already able to import virtualenv from my python shell anyway).
I just added the correct directory to my PATH and everything worked fine (the directory containing the virtualenv executable, i-e /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages which isn't included in my PATH by default despite being the directory virtualenv and other pip-installed tools was in).
Find where is your virtualenvwrapper located. in my case
~/.local/bin
May be it's installed in
/usr/local/bin/
It totally depends on the System or Package Manager you are using.
Add this path in your shell configuration .bashrc or .zshrc or whatever by simply
PATH=$PATH:<directory_you_want_to_add>
for example
PATH=$PATH:~/.local/bin
Also add the following configuration in .bashrc or .zshrc
# the path you want your virtual environments to be saved and loaded from
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/<project_folder>
# most important, this is the program which loads virtualenv
# please update the path where virtualenvwrapper.sh is located
source /usr/local/bin/virtualenvwrapper.sh
Don't Forget to restart the shell.. or reload the configuration...
To test whether it worked
mkvirtualenv test
if you see a test environment created then everything is ok.
For Detailed Installation Instructions go to the docs: virtualenvwrapper installation
For me it was:
export PYTHONPATH=/usr/bin/python3
export PATH=$HOME/.local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
I changed the line to:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
It worked.
ERROR: virtualenvwrapper could not find virtualenv in your path
This error means - program virtualenv is not in your system path. This mostly happens if you install virtualenv via pip without sudo. This kind of installation stores data in users local directory e.g ~/.local/bin. So first step is to find where this binary present. You can do that using locate program. First update its database using sudo updatedb. Then run locate *bin/virtualenv. Whatever path you get, append it in system path variable. This you can do by adding below line in your shell config file e.g. ~/.bashrc or ~/.zshenv.
export PATH=$PATH:/your/path
e.g.
export PATH=$PATH:~/.local/bin
Now open new shell and try again. Error should be gone.
In my case, I tested use this command:
sudo find / -name "virtualenv"
and I have a list with all path to this file,
I tested one to one and solved with path:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
My configurations to environment variables is :
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
in file .bashrc.
Now all its works.
The way I did it was (using zsh) in this way:
export PATH=$HOME/bin:/usr/local/bin:$PATH:/Users/username/Library/Python/2.7/bin:$PATH
I simply located the file of virtualenvwrapper.sh inside this path /Users/username/Library/Python/2.7/bin:$PATH
and added that path to PATH.
I have set the variable VIRTUALENVWRAPPER_VIRTUALENV in my .zshrc to the full path of the virtualenv binary and it works for me.
Here is my .zshrc file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/Library/Python/2.7/bin/virtualenv
source $HOME/Library/Python/2.7/bin/virtualenvwrapper.sh
Your PYTHONPATH makes me think you have Homebrew installed. It sounds like virtualenvwrapper was installed with either your system pip or your homebrew pip while it is being executed with the opposite python interpreter.
I had this same issues and tried many many things, what found as a solution is i had three pip version, pip with 2.7, 3.6 and 3.7. and 3.6 was the one works fine for many things, and install as sudo pip3.6 install virtualenv, and it works fine.
I would suggest, check your pip version and tried to install based on your pip ver.
Removing all virtualenv related packages would work.
pip freeze -l | grep ^virtualenv | awk -F= '{print $1}' | xargs pip uninstall -y
I am trying to find out why my virtualenv and/or virtualenv wrapper - installed using pip using homebrew - cannot be found. I think it's because it's not added to my PATH:
$ which virtualenv
$
and:
$ virtualenv someDir
$ -bash: virtualenv: command not found
I installed pip using homebrew, and virtualenv using pip, without problems. I tried reinstalling virtualenv, but that did not work either.
How do I know what path to add to PATH? Just the path that virtualenv.py seems to be installed into? That seems to be:
/usr/local/lib/python2.7/site-packages/virtualenv.py
I also found this guide, which suggests this:
$ ln -s ../Cellar/python/2.7/Frameworks/Python.framework/Versions/2.7/bin/virtualenv virtualenv
However, it does not help me run virtualenv. I am on Mac OSX 10.7.5 (Lion).
It seems that I myself am the exception to the rule for almost all 'simple' installation procedures. For some reason, it WAS a path related issue:
I ran brew info python, which outputted a lot of information. At the bottom I found this:
Executable python scripts will be put in:
/usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.
I added that to my PATH in /etc/launchd.conf and ~/.bashrc and lo and behold:
$ which virtualenv
tells me:
"/usr/local/share/python/virtualenv"
I still don't know why I couldn't find any pointers in the right direction, online, anywhere? Is pip install virtualenv supposed to add to the PATH itself? If so, why not on my system? Why did #bibhas tell me explicitly it was not a path issue?
Had the same issue after pip install virtualenv
When I inspected python ls -la /usr/local/bin/python I found it was symbolically linked to /Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I cd in that directory I also found the virtualenv executable and
Fixed it by
cd /Library/Frameworks/Python.framework/Versions/2.7/bin
ln virtualenv /usr/local/bin/virtualenv
Sidenote: I also happen to have a python installation in /System/Library/Frameworks/Python.framework/Versions/2.7/bin
I believe that's the one that came with OSX
In your .bashrc you need to have:
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
(Mac / Linux specific)
So I got an error message when I did a pip3 install --user --upgrade virtualenv telling me that I did not have Users/home/Library/Python/3.7/bin in my PATH. So I simply added it.
If this is on the Mac, the following did it for me
vi ~/.bash_profile
PATH="/Users/home/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
restart your terminal and type virtualenv env and that should do it.
I solved it by:
At first, I found out it is located at /usr/local/python3
and then I fixed it by the command:
ln virtualenv /usr/local/bin/virtualenv
This solution will give you an alternate tool to use and solve your virtualenv problem at the same time.
Use pythonbrew. It is inspired from rvm in the ruby world and is helpful in managing pythons on your system and also wrap virtualenv commands to provide virtual environment management. I use it Mountain Lion for my development purposes and have had no problems. More details (on my blog): http://stacktoheap.com/blog/2013/03/11/why-use-virtualenv-when-there-is-pythonbrew/
My idea is to add your virtualenv position to the BASH PATH
export PATH=$PATH:/usr/local/python2.7/bin
Or change your position
For those with Python 2.7, I came across this as well, and solved it by simply putting the following line into the \etc\paths file (may need to $ sudo chmod it first):
/Library/Frameworks/Python.framework/Versions/2.7/bin
Save the change and start a new Terminal session. Check it with echo $PATH
The module in /usr/local/lib/python2.7/site-packages is imported by a short script that uses pkg_resources.load_entry_point to run the application. The utility script should be in /usr/local/bin.