Ensurepip module not existing, how to install manually?
Asked Answered
I

2

6

In the interest of not getting an XY problem: the goal is to create a virtual environment on synology dsm, so no apt-get, where pip is installed manually.

I am trying to create a virtual environment, in above environment (synology dsm package python 3.8 with pip installed manually).

However this gives the following error:

$ python3 -m venv new_venv
Error: Command '['/volume1/docker/builder/new_venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

In the chain of finding that error I discovered that venv is working "just fine":

$ python3 -m venv --without-pip new_venv 

Works as expected. Also pip itself works as expected. However I had to install pip manually. This also has as consequence that the synology dsm version of python does not have the module ensurepip..

# python3 -c "import ensurepip; print(ensurepip.__file__);"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ensurepip'

This gives the problem: how does one manually install ensurepip, and/or make virtual env install pip without relying on ensurepip?

Ivanovo answered 18/1, 2021 at 18:52 Comment(1)
@phd yes pip is installed through that and correctly works - it's that venv depends on ensurepip which isn't installed.Ivanovo
E
7

On Ubuntu, it seems the module is not installed by default when installing Python. I managed to get it working by running

# Adjust for your python version
sudo apt-get install python3.8-venv
Expanded answered 20/9, 2023 at 9:31 Comment(0)
D
6

Install pip inside your venv virtual environment

Download the newest pip installation script and name the file get-pip.py:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Create the virtual environment with Python 3 but without pip inside it (assuming you are in /volume1/docker/builder/):

$ python3 -m venv --without-pip /volume1/docker/builder/new_venv

Activate the virtual environment:

$ source /volume1/docker/builder/new_venv/bin/activate

Your prompt should now contain the virtual environment name in parens:

(new_venv) $

The script will install pip inside the activated venv virtual environment:

(new_venv) $ python get-pip.py
# or
(new_venv) $ python3 get-pip.py
Dyaus answered 5/1, 2022 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.