4

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?

paul23
  • 8,799
  • 12
  • 66
  • 149
  • @phd yes pip is installed through that and correctly works - it's that `venv` depends on `ensurepip` which isn't installed. – paul23 Jan 18 '21 at 19:53

1 Answers1

4

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
Emil Carpenter
  • 1,163
  • 10
  • 19