ensurepip is disabled in Debian/Ubuntu for the system python
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?
24 Answers
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-pipensurepip 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.
install system python3 pip package
sudo apt-get install python3-pipcreate 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 Djangoor you may activate your virtual environment first
source myvenv/bin/activate
python3 -m pip install Djangopython3 -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
I had the same problem and installing python3-venv as instructed was not solving the ensurepip unavailability issue! However, since my python3 version is 3.7.5 installingpython3.7-venv` instead solved my issue.
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 pythonLook at this picture the result, maybe this help you, have a nice day!
I had a same problem and tried to run the command shown in the error
./venv/bin/python -Im ensurepip --upgrade --default-pipYou might see the output like this
Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.5/runpy.py", line 85, in _run_code exec(code, run_globals) File "/usr/lib/python3.5/ensurepip/__main__.py", line 4, in <module> ensurepip._main() File "/usr/lib/python3.5/ensurepip/__init__.py", line 268, in _main default_pip=args.default_pip, File "/usr/lib/python3.5/ensurepip/__init__.py", line 174, in bootstrap _run_pip(args + _PROJECTS, additional_paths) File "/usr/lib/python3.5/ensurepip/__init__.py", line 67, in _run_pip pip.main(args) File "/tmp/tmp_yqoc6jf/", line 215, in main File "/usr/lib/python3.5/locale.py", line 594, in setlocale return _setlocale(category, locale)
locale.Error: unsupported locale settingNotice this line locale.Error: unsupported locale setting means that you forgot to set locate.
So the solution is:
export LC_ALL=C
python3 -m venv venvand you'll ready to go.