How to update pip and keep the new version of pip portable (=use relative path to python.exe)?

120 Views Asked by At

I use WinPython as portable app on Windows and get following hint:

A new release of pip is available: 23.1.2 -> 23.2.1
[notice] To update, run: python.exe -m pip install --upgrade pip

If I run the command as suggested, the new version of pip stores the absolute path to python.exe.

If I move my IDE folder to another location, pip does not work any more:

pip list
Fatal error in launcher: Unable to create process using '"C:\python_env\App\WinPython\python-3.11.1.amd64\python.exe"  "D:\eis\python_env\App\WinPython\python-3.11.1.amd64\Scripts\pip.exe" list': The system cannot find the file specified.

=> Is there a way to tell pip to store a relative path to python.exe instead of an absolute one, so that pip remains portable?

=> Or is there some configuration file that I could fix after installing pip, for example some pip._pth file? Where to put it?

2

There are 2 best solutions below

0
Stefan On BEST ANSWER

WinPyton comes with a script file that fixes portability:

WinPython/scripts/make_winpython_movable.bat

1
Max On

You can use PIP_PREFIX environment variable

export PIP_PREFIX=~/.local/pip

This will set the PIP_PREFIX environment variable to the directory ~/.local/pip. This directory is created by Python when you install pip, and it is located in your home directory.

Once you have set the PIP_PREFIX environment variable, pip will store all of its files in the directory ~/.local/pip.

In the Edit environment variable dialog box, add the following path to the end of the Value field:

;~/.local/pip

Test it using : echo $PIP_PREFIX

The output of this command should be the path to the directory ~/.local/pip.