mkvirtualenv running without error but not creating the environment in zsh - python

I'm transitioning to zsh on my Mac (Catalina). So far so good except my virtualenv and virtualenvwrapper aren't working as expected. I've tried re installation with the following steps:
rm -rf ~/.virtualenvs # Delete all existing data.
pip uninstall virtualenv virtualenvwrapper # Remove
pip install virtualenv virtualenvwrapper # Reinstall
Added following lines to ~/.zshrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export WORKON_HOME="${HOME}/.virtualenvs"
source `which virtualenvwrapper.sh`
I now have access to the commands in zsh. but if I try to make an env with:
mkvirtualenv testenv
I get:
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/alesirowland/.virtualenvs/bin/python3.7
Not overwriting existing python script /Users/alesirowland/.virtualenvs/bin/python (you must use /Users/alesirowland/.virtualenvs/bin/python3.7)
Installing setuptools, pip, wheel...
done.
running lsvirtualenv returns no environments. It also appears to be trying to use 3.7 despite my environment variables written to default to python2.7. Going back into my bash console creates the env but also defaults to python3. What have I got wrong?
EDITs:
verbose output is generally asking to install in ~/.virtualenvs/bin rather than ~/.virtualenvs//bin
workon on an existing env just echos all of my envs to the screen.

Solution found! this line in my .zshrc is affecting virtualenvwrapper for some reason setopt KSHARRAYS

Related

"virtualenv is not compatible with this system or executable" using virtual env and anaconda

I'm trying to start up a virtual env using virtualenv, am getting this error:
Already using interpreter /Users/pkilcrease/anaconda/bin/python3
Using base prefix '/Users/pkilcrease/anaconda'
New python executable in /Users/pkilcrease/.virtualenvs/bodega/bin/python3
Also creating executable in /Users/pkilcrease/.virtualenvs/bodega/bin/python
ERROR: The executable /Users/pkilcrease/.virtualenvs/bodega/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/Users/pkilcrease/.virtualenvs' (should be '/Users/pkilcrease/.virtualenvs/bodega')
ERROR: virtualenv is not compatible with this system or executable
The command I am running is mkvirtualenv -a . --no-site-packages --python='which python3' -r requirements.txt bodega
My .bashrc file currently looks like this:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_SCRIPT=/Users/pkilcrease/anaconda/bin/virtualenvwrapper.sh
source /Users/pkilcrease/anaconda/bin/virtualenvwrapper_lazy.sh
I have the feeling that there is some issue with anaconda and virtualenv which is causing the problem here, but not sure how to remedy that or if it's just a red herring.
If using a conda python executable, use conda create --name {your_venv} python=3 (note there is a virtualenv utility that comes with conda, but still use conda create... to make new virtual env's).
Otherwise, when using a version of python installed by the system package manager, create a virtual env using virtualenv, or preferably using the virtualenvwrapper utility mkvirtualenv. For example on Linux, the "system python" is /usr/bin/python3, /usr/bin/python, /usr/bin/python2, etc. Or, as it's clear you're on MacOS, that would likely be a python installed by brew (homebrew) or port (macports) in /opt or /usr/local. You may have to install virtualenvwrapper in order to get mkvirtualenv (and lsvirtualenv, etc).
In short, if you're using anaconda python, stick with conda utils. Else, if you're keeping your python free & open (as many of your corp IT data centers do), then use any of the various open utils like mkvirtualenv, etc.
Hopefully this may help people still looking at this question, but an easy fix:
conda install -y virtualenv

Pip3 packages can't be found/used by the terminal

I'm trying to use python3's built in pip3 package manager to install virtualenv and Django so I can learn more about python but after installing them both and trying to use virtualenv, the terminal throws:
zsh: command not found: virtualenv
But I can see that the virtualenv is installed on:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
I also tried creating a symlink to virtualenv.py to /usr/local/bin but when I try to run virtualenv in the terminal its giving me zsh: permission denied: virtualenv
I'm on a OS X machine. I installed Python 3 along side Python 2.7, which the machine came with.
Has anyone experience this problem before? I'd appreciate any advice/solution you guys could give. Thanks in advance!
You might use Bash before using Zsh. And the python had been updated when you used Zsh.
I got the same problem. Zsh could not find python3 packages. But when I changed the shell to Bash, the python3 packages could be found.
I solved the problem in the way as follows:
Open the terminal and input the command:
nano .bash_profile
Copy the settings in the .bash_profile:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Input the command:
nano .zshrc
Paste the code to the end of the .zshrc.
(.bash_profile is the settings file of Bash, .zshrc is the settings file of Zsh)
Restart the terminal.
Try to find the python3 packages, such as virtualenv:
which virtualenv
You may find the PATH of virtualenv.

Error message for virtualenvwrapper on Mac OS X Yosemite 10.10.3

I recently did a clean install of Mac OS 10.10.3 and am trying to set up a python environment. But I can't get virtualenvwrapper to work.
I installed python 2 and 3 using Homebrew.
$ which python
/usr/local/bin/python
$ which python3
/usr/local/bin/python3
$ which pip
/usr/local/bin/pip
$ which virtualenv
/usr/local/bin/virtualenv
$ which virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh
Here are the lines in my .bash_profile
export PATH=/usr/local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
The virtualenv works on its own with: $ source bin/activate
But when I source the virtualenvwrapper.sh. I get the following error message.
/usr/local/opt/python/bin/python2.7: 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/local/bin/python and that PATH is
set properly.
I can't figure out what went wrong. When I echo VIRTUALENVWRAPPER_PYTHON in the terminal. It returns the right path. In fact, all my paths are correct. They all point to the homebrew directory.
How can I get it to work?
It has been some time since this question was asked, but encountering the same issue, I'd like to add my solution in case someone might find it usefull:
Since virtualenvwrapper was installed using Python3, it is axpected that VIRTUALENVWRAPPER_PYTHON variable will point to Python3 path and not the Python2 path.
That is, in .bash_profile change:export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
To:export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
Then you can start using virtualwrapper, even if not installed for Python2 (unless you want to explicitly create the environment using Python2 in which case you'd probebly have to install it using pip2 and specify the relevant python path on the virtual environment creation command).
Per our comment exchange, you've installed virtualenvwrapper only on
python 3. You need to also install it on python2. To do so:
curl -O https://bootstrap.pypa.io/get-pip.py python2.7 ./get-pip.py
--user ~/.local/bin/pip install virtualenvwrapper My own setup is the opposite -- I use python2 for work, so install virtualenv for 3.x in
~/local -- hope that helps.
Thank you very much. Your answer points me to the right direction.
I solved the problem by uninstalling all things virtualenv.
pip uninstall virtualenv virtualenvwrapper
Then I installed everything again using pip2.7.
pip2.7 install virtualenv virtualenvwrapper
Now the terminal doesn't complain about can't find the module when I source virtualwrapper.sh
. /usr/local/bin/virtualenvwrapper.sh
However, python3 is the default python.
$ mkvirtualenv myenv
Using base prefix '/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4'
New python executable in myenv/bin/python3.4
Also creating executable in myenv/bin/python
Installing setuptools, pip...done.
To create a python2 env. I need to do this:
$ mkvirtualenv myenv --python /usr/local/bin/python
Running virtualenv with interpreter /usr/local/bin/python
New python executable in myenv/bin/python2.7
Also creating executable in myenv/bin/python
Installing setuptools, pip...done.
Per our comment exchange, you've installed virtualenvwrapper only on python 3. You need to also install it on python2. To do so:
curl -O https://bootstrap.pypa.io/get-pip.py
python2.7 ./get-pip.py --user
~/.local/bin/pip install virtualenvwrapper
My own setup is the opposite -- I use python2 for work, so install virtualenv for 3.x in ~/local -- hope that helps.
This has fixed my issue
Assuming you have already added an alias for python2 (the default version of python in mac)
Add these on ~/.bash_profile
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3'
source /usr/local/bin/virtualenvwrapper.sh
just modify the VIRTUALENVWRAPPER_PYTHON environment variable into this:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
and then run it by typing
source ~/.bash_profile

virtualenv not pointing to local executables

I've noticed strange behavior of virtualenv installed on my local machine. This is what I've been doing:
tomasz#laptop:~/Development/Python$ virtualenv nac-env
New python executable in nac-env/bin/python
Installing Setuptools...................................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
tomasz#laptop:~/Development/Python$ cd nac-env
tomasz#laptop:~/Development/Python/nac-env$ source ./bin/activate
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which python
/usr/bin/python
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which pip
/usr/bin/pip
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which easy_install
/usr/local/bin/easy_install
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ echo $PYTHONPATH
/usr/lib/python2.7/site-packages:/usr/lib/python2.7/dist-packages
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ deactivate
tomasz#laptop:~/Development/Python/nac-env$
As the nettuts screencast says (http://www.youtube.com/watch?v=IX-v6yvGYFg, 6:55), python, pip and easy_install executables should point to files inside the virtual environment and not to /usr/bin/... stuff. If the $PYTHONPATH sysvar is set incorrectly, I think that my installation doesn't work as expected... Does anyone know what's going wrong?
PS I have installed virtualenv globally on my local machine some time ago. Probably it was intalled through pip or sth like that.
Well, I made myself sure this behavior I had in fact is not normal. I've uninstalled existing virtualenv and re-installed it from pip and now everything works perfectly:
tomasz#laptop:~/Development/Python/foo$ source bin/activate
(foo)tomasz#laptop:~/Development/Python/foo$ which python
/home/tomasz/Development/Python/foo/bin/python
(foo)tomasz#laptop:~/Development/Python/foo$ which pip
/home/tomasz/Development/Python/foo/bin/pip
(foo)tomasz#laptop:~/Development/Python/foo$ which easy_install
/home/tomasz/Development/Python/foo/bin/easy_install
(foo)tomasz#laptop:~/Development/Python/foo$ echo $PYTHONPATH
/usr/lib/python2.7/site-packages:/usr/lib/python2.7/dist-packages
I had this happen to me. Did you change your project path?
When I first created the virtual environment, I used ~/src/my_project/venv but later changed it to ~/projects/my_project/venv. When I ran the activate scripts, it was using the old path. To fix this, I did a substitution on all of the scripts in the activate directory with the new path and python, pip, etc. were now sourced from the virtual environment.

Why does pip installs a package outside my virtual environment?

After doing a source of the virtual environment I try
pip install -U --no-deps django-social-auth
and it returns:
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.6/dist-packages/django_social_auth-0.6.9-py2.6.egg-info/dependency_links.txt'
Why is it trying to write outside the virtualenv?
I ran into this problem when I renamed the directory containing my virtual environment. The hard path pip was using was no longer correct.
Update the shebang in the pip script to point to your virtual environment's python executable.
In my opinion, either you are executing a pip that is not part of the virtualenv, or you are, but the python interpreter that gets executed is not part of the virtualenv. Check if the pip you are executing is the right one with which pip, and force the python from the virtualenv by using your_envdir/bin/python pip <arguments>, instead of just invoking plain pip.
This is strange, because if you correctly activated the environment with bin/activate, you should get the correct pip. Are you sure you activated with . bin/activate, and not sh bin/activate ? They are two different things. Did the prompt change ?
you should probably make sure that you the pip from you virtual environment, so sth. like
./env/bin/pip install -U --no-deps django-social-auth
I ran into this problem when I had mistakingly set PYTHONPATH incorrectly in ~/.bashrc. If echo $PYTHONPATH returns anything outside your expected environment, delete it with export PYTHONPATH='' and check your ~/.bashrc for PYTHONPATH.

Categories