Virtualenvwrapper not found - python

Given what I know about Python, the problem I'm having shouldn't been happening. I installed virtualenvwrapper on Mac OS X Snow Leopard with pip. It's there in /Library/Python/2.6/site-packages. But when I try to import virtualenvwrapper, Python tells me there's no such module with that name. Other modules (e.g. virtualenv) load just fine, and /Library/Python/2.6/site-packages is right at the top of my Python path. So is there something weird about virtualenvwrapper so that Python isn't finding it?

Mine is in /usr/local/bin/virtualwrapper.sh but you should be able to add this to your .bashrc, .bash_profile, or .profile to put into your environment. (Remember to do source .bashrc or open a new terminal window)
source /Library/Python/2.6/site-packages/virtualenvwrapper.sh
EDIT Here's my entire bash profile related to pip, virtualenv and virtualenv wrapper since it looks ugly as a comment
# python
export PATH=/usr/local/share/python:$PATH
export PYTHONPATH=/usr/bin/python:$PYTHONPATH
export PATH=/usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
export VIRTUALENVWRAPPER_PYTHON=/usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin/python
#virtualenv wrapper
export WORKON_HOME=~/.virtualenvs
# mkvirtualenv --no-site-packages myenv
source /usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true

Try installing virtualenvwrapper with **sudo** pip virtualenvwrapper. It might be referring to the shell script it installs in /usr/local/bin.

I am on Mac OS X 10.9.2 with XCode 5.1.1 and for me virtualenvwrapper.sh file was present in
/usr/local/bin/virtualenvwrapper.sh
So I simply copied this into ~/.profile file:
source /usr/local/bin/virtualenvwrapper.sh
And now my ~/.profile file looks something like this:
# MacPorts Installer addition on 2014-02-23_at_17:28:39: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
source /usr/local/bin/virtualenvwrapper.sh
And now I am able to use virtualenvwrapper commands without any issue whatsoever
Hope this helps!

This worked for me:
source ~/.bashrc

Related

virtualenvwrapper.sh crashes shell

I am following the install instructions for virtualenvwrapper, described here.
I have used pip install virtualenvwrapper and it installed at the path /home/.pyenv/shims/.
But when I run the command
source /home/.pyenv/shims/virtualenvwrapper.sh the whole Konsole shuts down.
I had previously put the command in the .bashrc file and almost broke Linux because the Konsole would crash immediately after opening.
I'm using Linux OpenSuse and Python version 3.6.0.
Any ideas what could be causing the crash?
I found a solution.
source ~/.pyenv/versions/VERSION/bin/virtualenvwrapper.sh works every time.
You can't use the shims directory for some reason. Maybe since virtualenvwrapper was likely installed into the pyenv version directory. If you use the shims directory, that link could break when switching versions with pyenv. It's better to access it directly.
I'm seeing the same thing on MacOS (10.12.6).
For me the .zshrc entry which closes/ends the terminal window is:
source $HOME/.pyenv/shims/virtualenvwrapper.sh
I also would like to know why this is occurring, and how to fix it.
I have come across this problem several times now on different machines and while I don't fully understand why it happens, I have found a solution to the problem.
The problem seems to be due to mismatches in the python version being used and the pip version used to install virtualenvwrapper. I had been using the system install of python (2.7) but the pip version was for python 3.5.
To fix this, use the suggestion in this answer as follows:
python -m pip install virtualenvwrapper
Then you can source /path/to/virtualenvwrapper.sh and everything should work fine.
Sean Combs' answer works for me, too. But I didn't want to hard code a specific python version, so I use grep to build the path to virtualenvwrapper.sh dynamically.
export VIRTUALENVWRAPPER_PYTHON=$HOME/.pyenv/shims/python
source $HOME/.pyenv/versions/$($VIRTUALENVWRAPPER_PYTHON -V 2>&1 | grep -Po '(?<=Python )(.+)')/bin/virtualenvwrapper.sh
To add to Sean's answer since I don't have enough reputation to add a comment, adding
export PYENV_VERSION="$(pyenv version-name)"
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh
to your .bashrc (or .zshrc in my case) allows you to point to the correct virtualenvwrapper.sh even if you change python versions without hardcoding or grep
I had this problem on Mac and I found that zsh crashes
with line
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh
if you not specified VIRTUALENVWRAPPER_PYTHON variable
So this's my .zshrc (or .bashrc) config for pyenv and virtualenvwrapper on fresh user
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export PYENV_VERSION="$(pyenv version-name)"
VIRTUALENVWRAPPER_PYTHON="$HOME/.pyenv/shims/python"
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh
# Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
# Set the pyenv shims to initialize
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
I had a same problem, and I solved it by installing virtualenvwrapper with builtin python(e.g. /usr/bin/python3), not a pyenv python runtime, though the builtin one is not used in actual workspaces.
In your ~/.bashrc or ~/.zshrc, putting:
export PYENV_VERSION="$(cat $HOME/.pyenv/version)"
source "$HOME/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh"
works for me.

There is something wrong with virtualenvwrapper setting

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.

ERROR: virtualenvwrapper could not find virtualenv in your path

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

how to modify pip install path on mac os 10.10

I want to use python3.4 as the default version and install extra packages to python3 by pip or easy_install. I have installed python3.3 and python3.4 on my mac.
To change the default python version, aka, python command will go to python3.4 instead python2.7, I added a file called .bash_aliases with alias python='python' in it, then source the file. The method works until I restart terminal. Moreover I added export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4/" into .bash_profile then source it, but the version doesn't change.
I have these environment variables set up in .bash_profile, but don't know how to change even after googling and having tried different strategies. Some lines in my .bash_profile:
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/Java/Home//bin"
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/directory-you-do-development-in
source /usr/local/bin/virtualenvwrapper.sh
##
# Your previous /Users/john/.bash_profile file was backed up as /Users/jonh/.bash_prof ile.macports-saved_2014-02-09_at_13:58:24##
export PATH=/usr/local/bin:$PATH
# MacPorts Installer addition on 2014-02-09_at_13:58:24: adding an appropriate PATH variable for u se with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
##
# Your previous /Users/john/.bash_profile file was backed up as /Users/john/.bash_prof ile.macports-saved_2014-02-09_at_14:02:11
##
# MacPorts Installer addition on 2014-02-09_at_14:02:11: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
export PATH=/Library/Frameworks/Python.framework/Versions/3.4/bin:$PATH
I know there is a temporary way python3 -m pip install somepPackage from official manual, but is there a way to change the install path permanently?

How to add virtualenv to path

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.

Categories

Resources