Skip to content
Advertisement

pip with embedded python

I installed embedded python from here, titled “Windows x86-64 embeddable zip file”, but it does not have pip installed, it does not have site-packages either, when I try to do python get-pip.py it failed to run because this file has import pip in it. So how can I install pip within a embedded python environment.

Traceback (most recent call last): File “.getpip.py”, line 20061, in main() File “.getpip.py”, line 194, in main bootstrap(tmpdir=tmpdir) File “.getpip.py”, line 82, in bootstrap import pip File “”, line 961, in _find_and_load File “”, line 950, in _find_and_load_unlocked File “”, line 646, in _load_unlocked File “”, line 616, in _load_backward_compatible

The directory structure is:

JavaScript

Advertisement

Answer

I recently ran into the same issue. I checked the documentation for pip and they seem to say that this use case isn’t supported etc. But anyhow, here is my hack for getting the modules to work.

I installed, and by that I mean unzipped embedded python into a directory called d:python. I assumed that the modules are going to live in that same directory.

First, to install the pip module, I needed to save the extraceted files. I changed the get-pip.py using a text editor that supported unix line terminators by removing the rmtree lines that remove the temporary and unpacked tree from the blob containted in the get-pip.py file.

I changed both locations, but only the last one was needed. The line that I changed in two locations read

JavaScript

and I modified it thus (I didn’t want to bother with the python indentation blocks):

JavaScript

I now ran my python D:pythonpython.exe on the modified get-pip.py and found the temporary directory where the files were unzipped to.

I copied this directory, (check that it contains a main.py) file into the python install D:pythonpip (this is where I wanted my modules to live), ensuring that the D:pythonpip directory contained the main.py file.

The pip module is now installed in the python directory, but you need to hack pip further to remove the exception above. I did this by changing the locations.py file (in my case located in D:pythonpiplocations.py) to return the bin_py and bin_user locations of D:python.

ie:

JavaScript

I had to change the user_dir for pip to somewhere that would persist on this drive that was shared across multiple VMs.

The pip module now runs fine, eg

d:pythonpython.exe -m pip …

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement