malikarumi@Tetouan2:~$ pip install virtualenv
Collecting virtualenv
Downloading virtualenv-12.0.7-py2.py3-none-any.whl (1.8MB)
100% |################################| 1.8MB 330kB/s
malikarumi@Tetouan2:~$ pip freeze
(a lot of stuff, but not virtualenv)
malikarumi@Tetouan2:~$ virtualenv testvenv1
The program 'virtualenv' is currently not installed. You can install it by typing:
sudo apt-get install python-virtualenv
What is going on here? is python-virtualenv == pyvenv? Isn't that still broken? Does original virtualenv still work with python?
if venv (too many name variations!!!) is part of the standard library, https://docs.python.org/3/library/venv.html, why am I being told to install it?
And when I did try to install it, I got:
malikarumi@Tetouan2:~$ sudo apt-get install python-virtualenv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
python-colorama python-distlib python-html5lib python-pip python-setuptools
At which point I aborted, because installing python3-pip just before that had given me
Setting up python3-setuptools (3.3-1ubuntu1) ...
Setting up python3-pip (1.5.4-1) ...
And I wasn't sure if the extra packages would overwrite them or go onto python 2.7.
I read that python 3 is supposed to be the default going forward. Since both 2.7 and 3.4 are there, and have separate commands, how do I not only make sure Python 3 is my default, but that anything I install goes there and is used by it instead of 2.7?
BTW, I tried sudo apt-get python3-virtualenv and got: E: Unable to locate package python3-virtualenv
Best Answer
The way to install Python 3.x packages in a Python virtual environment is to create the Python virtual environment using Python 3 virtual environment creator (python3-virtualenv). python3-virtualenv is in the default Ubuntu repositories in Ubuntu 14.10 and later.
Install Python 3.x packages in a Python virtual environment in 16.04 and later
Install Python 3 virtual environment creator
Create a Python virtual environment for python3. You can only install python3 packages inside this Python virtual environment. If you also want to install Python 2.x packages, then you need to make another Python virtual environment.
The new Python virtual environment for python3 will be created in the
env
directory which is located in the current directory.Install Python packages.
This is a new python3 virtual environment with the latest version of pip3, so installing Python packages in it will work great.
Install Python 3.x packages in a Python virtual environment in Ubuntu 14.04
Add the following line to the end of .bashrc.
Save the changes to .bashrc and close gedit. Source your .bashrc for the changes to take effect.
Create a Python virtual environment for python3. You can only install python3 packages inside this Python virtual environment. If you also want to install Python 2.x packages, then you need to make another Python virtual environment.
The new Python virtual environment for python3 will be created in the
~/.virtualenvs/py3
directory..virtualenvs
is a hidden folder.Install a package.