I am trying to make a virtual environment for the development of my Django application. The commando's which I am using:

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']


vagrant@vagrant:/var/www/djangogirls$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-venv is already the newest version (3.5.1-3).
The following packages were automatically installed and are no longer required:
  javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore python-pbr python-pkg-resources
  python-six python-stevedore python3-virtualenv virtualenv virtualenv-clone
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.

vagrant@vagrant:/var/www/djangogirls$ python3 -m ensurepip
ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules for the system python are usually handled by dpkg and apt-get.

    apt-get install python-<module name>

Install the python-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.


vagrant@vagrant:/var/www/djangogirls$ rm -r myvenv/ 

vagrant@vagrant:/var/www/djangogirls$ python3 -m venv myvenv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/var/www/djangogirls/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

As you can see, I am trying to make a myvenv, which cannot be created due to the python3-venv missing. I have already installed this, but the ensure pip is missing. After searching it seems that the system (Ubuntu 16.04) discourages the usage of the package. Could someone help me work around this problem?

  • The actual command that's failing is /var/www/djangogirls/myvenv/bin/python3 -Im ensurepip ..., which maybe failing for entirely different reasons. – muru Feb 3 '17 at 14:37

There is a related bug report here

ensurepip component is missing/disabled on Ubuntu

The way around it is to create a virtual environment without pip

python3 -m venv myvenv --without-pip

ensurepip component isn't called and a new environment is created in this case.

However missing pip in virtual environment can be a problem.

One solution is to install system pip3 package and use system pip module inside your virtual environment directly.

Virtual environment has to have access to system site packages to be able to use system pip module.

  1. install system python3 pip package

    sudo apt-get install python3-pip
    
  2. create virtual environment without pip and with access to system site packages

    python3 -m venv myvenv --without-pip --system-site-packages
    

You can use system pip module to install python packages into your virtual environment now.

Instead of pip install Django you have to use explicit

myvenv/bin/python3 -m pip install Django

or you may activate your virtual environment first

source myvenv/bin/activate
python3 -m pip install Django

python3 -m pip --version may comes handy to see which python environment is used.

Based on solution found here, but don't use proposed python get-pip.py in virtual environment, because it will steal system pip command

Anaconda involucred

If you are using Anaconda or Conda this solution may help you:

Conda manages python itself as a package, so that conda update python is possible, in contrast to pip, which only manages Python packages. Conda is available in Anaconda and Miniconda (an easy-to-install download with just Python and conda).

very disturbing for me but well, hands to the keyboard in a terminal window:

conda update python

Look at this picture the result, maybe this help you, have a nice day!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.