Python virtualenvwrapper not creating empty environment when used with Fedora 20 - python

I installed virtualenvwrapper using the following steps in Fedora 20:
$ sudo pip install virtualenvwrapper
$ export WORKON_HOME=$HOME/.virtualenvs
$ export PROJECT_HOME=$HOME/Devel
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv -p /usr/bin/python2 test
So far so good, but when I check the environment, test, that I created it included all the existing python dependencies on my system. Here's a small sample of what's included when the virtualenv is created:
$ pip freeze
tornado==2.2.1
urlgrabber==3.10.1
vboxapi==1.0
virtualenv==1.11.6
virtualenv-clone==0.2.4
virtualenvwrapper==4.3.1
I've never had this issue with Ubuntu so it makes me think the problem is related to how virutalenvwrapper is interacting with Fedora 20. Please let me know what you think.
EDIT: Included the virtualenv section of my .bashrc file after a suggestion to add --no-site-packages
# Virtualenvwrapper
alias pip="pip-python"
export WORKON_HOME=$HOME/virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
source /usr/bin/virtualenvwrapper.sh

Related

FileExistsError: [Errno 17] File exists: '/usr/bin/python' -> '/home/had2000/.virtualenvs/cv/bin/python'

When i have python 3.5 and python 3.6 on ubuntu .I entered some alternate commands to use python 3.5 only (when I type python -V and python3 -V the same output is 3.5.2)
And then i install virtualenv and virtualenvwrapper — these packages allow me to create and manage Python virtual environments:
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/get-pip.py ~/.cache/pip
To finish the install of these tools, I updated our ~/.bashrc file.I added the following lines to your ~/.bashrc :
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Next, source the ~/.bashrc file:
$ source ~/.bashrc
And final I created your OpenCV 4 + Python 3 virtual environment:
$ mkvirtualenv cv -p python3
i have created the virtual environment but had some problems in the back end and i guess it was due to the presence of python3.6. In the end i decided to uninstall python 3.6 and rerun the steps above from scratch and had a problem at the last step that I mentioned above.When i enter command "mkvirtualenv cv -p python3" i get an ERROR:
FileExistsError: [Errno 17] File exists: '/usr/bin/python' -> '/home/had2000/.virtualenvs/cv/bin/python'
At the same time when i enter the command "update-alternatives --config python" python3.6 is no longer there,but i get a warning:
update-alternatives: warning: alternative /usr/bin/python3.6 (part of link group python) doesn't exist; removing from list of alternatives
There is 1 choice for the alternative python (providing /usr/bin/python).
Looking forward to your help, thank you
From the commands you've shared, the error arises from the mkvirtualenv cv being run twice - i.e. the environment already exists. To remove the environment you created, do: rmvirtualenv env-name-here which in this case will become rmvirtualenv cv. This shouldn't be done with that environment active, BTW. An alternate route is to delete $WORKON_HOME/env-name-here. By default, $WORKON_HOME is usually .virtualenvs.

Initializing virtualenvwrapper for Python 3.6 on MacOS

I would like to use virtualenvwrapper with Python 3.6, however, I am working on a Mac which defaults to using Python 2.7 and I am having issues. Here's what I have done so far. Using the following commands, I have found the locations of where each Python version is saved:
>> which python
>> /usr/bin/python
>> which python3
>> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
I have successfully installed virtualenv and virtualenvwrapper using:
>> pip3 install virtualenv
>> pip3 install virtualenvwrapper
I then search for the location of virtualenv and virtualenv wrapper to confirm their locations:
>> pip3 show virtualenv
>> Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
>> pip3 show virtualenvwrapper
>> Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
If I go to this site-packages directory there is the following:
virtualenvwrapper
|--- __pycache__
|--- hook_loader.py
|--- project.py
|--- user_scripts.py
virtualenvwrapper-4.8.2-py2.7-nspkg.pth
virtualenvwrapper-4.8.2.dist-info
According to virtualenvwrapper's documentation, I should add the following to my shell startup file to ensure initialization, changing virtualenvwrapper's path to the one set on my machine:
export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
I then searched for where virtualenvwrapper.sh is actually located (for some reason, it is not located where the virtualenvwrapper module is installed):
>> which virtualenvwrapper.sh
>> /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
I changed my .bashrc file using:
>> nano ~./bashrc
Copied in the following:
# script for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
I then opened up a new terminal and ran:
>> source `which virtualenvwrapper.sh`
Which gave me:
/usr/bin/python3: 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/bin/python3 and that PATH is
set properly.
What I don't understand is why virtualenvwrapper needs to be located at /usr/bin/python3 which is not a directory. Since it is in bin, it is also impossible for me to make it a directory. Additionally, the virtualenvwrapper.hook_loader is not where virtualenvwrapper.sh is which I think may be causing an issue.
I also tried creating a symbolic link to /usr/local/bin because some people stated that it solved their issue but this didn't solve mine:
sudo ln /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh
Another issue altogether is whether or not I need to install it using pip3 if I want to use virtualenvwrapper for Python3. For example, this post states that you only need to pass a flag, however, you should also be wary of installing it on your base Python installation.
Add
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
to .bashrc and execute the command in the terminal. That sets the path to Python interpreter for virtualenvwrapper.

Python virtualenv: Why is pip still looking in a non-$path path?

I've been keeping all my python2.7 installs in my ~/.local/ directory that way I don't have to sudo every time I want to do a pip install. I also have $HOME/.local/lib/python2.7/site-packages on my $PYTHONPATH. This has worked well for years but now I find myself needing to run python3 programs more frequently. After much research it seems like virtualenv is the most recommended way to deal with python 2 and 3 on the same system. But I am running into troubles. I can spin up a python3 virtual environment but when I try to install new libs with pip, my old global path (i.e. ~/.local/) is still being searched by pip, which makes sense. However, this is even the case if I remove my ~/.local/bin/ directory from my $PATH and unset my $PYTHONPATH.
Here is are the steps I took:
First check the preliminaries before activating virtualenv. (I'm on Ubuntu 16.04 btw)
maddoxw#firefly:~$ echo $PATH
/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
maddoxw#firefly:~$ echo $PYTHONPATH
maddoxw#firefly:~$ python --version
Python 2.7.12
maddoxw#firefly:~$ python3 --version
Python 3.5.2
maddoxw#firefly:~$ which pip
Since I removed my ~/.local/bin directory from my path, then I can be certain pip will not be found. Also, $PYTHONPATH is still empty. Now I create my virtualenv:
maddoxw#firefly:~$ mkdir test && cd test/
mkdir: created directory 'test'
maddoxw#firefly:~/test$ python3 -m venv .env
maddoxw#firefly:~/test$ source .env/bin/activate
(.env) maddoxw#firefly:~/test$ echo $PATH
/home/maddoxw/test/.env/bin:/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
(.env) maddoxw#firefly:~/test$ echo $PYTHONPATH
(.env) maddoxw#firefly:~/test$ which python
/home/maddoxw/test/.env/bin/python
(.env) maddoxw#firefly:~/test$ python --version
Python 3.5.2
(.env) maddoxw#firefly:~/test$ which pip
/home/maddoxw/test/.env/bin/pip
Good. My ~/.local/ is still NOT on my $PATH, $PYTHONPATH is still empty, python points to the correct path and version, and pip is pointing to the correct location. Now lets try to pip install a fresh lib.
(.env) maddoxw#firefly:~/test$ pip install Cython
Requirement already satisfied: Cython in /home/maddoxw/.local/lib/python2.7/site-packages
Why is pip still looking in a non-$PATH path?
First, install pip3 to use with python3. You can install it with the following command and then use pip3 to install your packages.
sudo apt-get install python3-pip
[Solved]
When I initially set up my python2.7 environment way back when, I created for myself a handy little function wrapper around pip so that I wouldn't have to type out the --user every time I wanted to pip install
pip() {
if [ "$1" = "install" -o "$1" = "bundle" ]; then
cmd="$1"
shift
$HOME/.local/bin/pip $cmd --user $#
else
$HOME/.local/bin/pip $#
fi
}
I put this function in ~/.bash.d/bash_functions
and in my ~/.bashrc i added the line,
[ -f ~/.bash.d/bash_functions ] && source ~/.bash.d/bash_functions
So, although I removed $HOME/.local/ from my path. This wrapper function was still being called everytime I fired up a new terminal. Weather or not I was or was not in a virtualenv was irrelevant.
Solution?
Commented out (or delete completely) the function wrapper fixed it.

Virtual environment doesn't work on Cloud9

Cloud9 (an online ide) doesn't seem to support my virtual environment:
me:~/workspace/dir (master) $ source venv/bin/activate
(venv) me:~/workspace/dir (master) $ which python
/usr/bin/python
This same virtual directory worked fine on my local machine:
(venv) me$ which python
/Users/me/dir2/dir/venv/bin/python
How can I fix this?
The following works for me.
sudo apt-get install python3.5-venv
python3.5 -m venv --clear ./mypy3.5/
source ./mypy3.5/bin/activate
It uses the
(mypy3.5) $ which python
/home/ubuntu/mypy3.5/bin/python
But there is a gotcha which might have been your problem. The python3 -m venv uses soft links to how your python resolves in your environment. I had Python 3.3, 3.4 and 3.5 installed in /usr/local so the /usr/local/bin/python3 would change and break my Python3 venv. Note that "python3" is evaluated for the environment not for an absolute path. To be careful, when there are more than one Python 3 on you system, create your virtual environment with an explicit path like the following.
/usr/bin/python3.5 -m venv --clear ./mypy3.5/
source ./mypy3.5/bin/activate
ls -l $(which python3.5)
/home/ubuntu/mypy3.5/bin/python3.5 -> /usr/bin/python3.5*

Problems installing virtualenvwrapper - No module named virtualenvwrapper

I trying install virtualenvwrapper from your official guide http://virtualenvwrapper.readthedocs.org/en/latest/install.html
I install virtualenvwrapper with pip and when I define the environment variables and source
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
I reboot my shell and I get the following output.
bgarcial#el-pug:~$ bash
/usr/local/bin/python: 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 virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is
set properly.
bgarcial#el-pug:~$
Despite this, the commands mkvirtualenv and others works. But .. What does this mean? How I can fix it? Thanks
What is the content of your ~/.bashrc file?
You may be calling "virtualenvwrapper" instead of "virtualenvwrapper.sh"
OR:
You may be exporting variables for the current shell that don't persist or propagate to subsequent shells.
The following script will install virtualenvwrapper and configure bash to persist the environment variables, which should in turn make virtualenvwrapper work as expected.
pip install virtualenvwrapper
configure_bashrc(){
echo '
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
' >> ~/.bashrc
source ~/.bashrc
}
[[ -z $(grep virtualenv ~/.bashrc) ]] && configure_bashrc

Categories

Resources