11

I'm trying to get pip on my USB drive. Following the instructions on this web sit, I downloaded get-pip.py and run python get-pip.py (python is in the environment path). Unfortunately the script through an error. I have uploaded the log file to here. The error itself is:

Exception:
Traceback (most recent call last):
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2251, in parsed_version
    return self._parsed_version
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2344, in __getattr__
    raise AttributeError(attr)
AttributeError: _parsed_version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2259, in version
    return self._version
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2344, in __getattr__
    raise AttributeError(attr)
AttributeError: _version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\commands\install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\req.py", line 1420, in install
    if existing_distribute in distribute_requirement:
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2643, in __contains__
    if self.index: item = item.parsed_version  # only get if we need it
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2253, in parsed_version
    self._parsed_version = pv = parse_version(self.version)
  File "c:\users\elyashic\appdata\local\temp\tmprkcrtx\pip.zip\pip\_vendor\pkg_resources.py", line 2267, in version
    "Missing 'Version:' header and/or %s file" % self.PKG_INFO, self
ValueError: ("Missing 'Version:' header and/or PKG-INFO file", distribute [unknown version] (i:\portableapps\portable python 3.2.5.1\app\scripts))

Can any one explain to me what I did wrong?

I'm using portable python 3.2.5.1, and it was fresh from the installation until I tried installing pip.

elyashiv
  • 3,623
  • 2
  • 29
  • 52

4 Answers4

12

Ok, if by Portable Python you mean the embeddable zip file that Python.org provides, than this guide solved my problem: https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/

Here's the text in case it goes offline:

To install Python on Windows download the latest version. In this example Python 3.6.5.

Extract the zip file to an directory, e.g. D:\python3.6.5.

To install pip download the latest version of get-pip to the pythons install path and start installation.

> d:\> cd /d D:\Python3.6.5 D:\Python3.6.5> python get-pip.py ...
> Installing collected packages: pip, setuptools, wheel Successfully
> installed pip-10.0.1 setuptools-39.2.0 wheel-0.31.1

If you are behind a proxy add the –proxy switch

D:\Python3.6.5> python get-pip.py --proxy="http://192.168.254.1:8888"

Unfortunately in the default configuration you can not load any module installed by pip, pip itself too. Because the sys.path variable just contains Python Zip file and the path to the python directory where the python executable is located.

>>> import sys
>>> print(sys.path)
['D:\\Python3.6.5\\python36.zip', 'D:\\Python3.6.5']
>>> import pip
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pip'

Any try to expand the variable by setting a PYTHONPATH variable are ignored. Root cause is that the embeddable zip file installation package contains a file python36._pth which overwrites all other possibilities to set the sys.path variable. sys.path contains all directories where python looks for modules.

To set the sys.path variable open the _pth file an add the following pathes at the and of the file. Replace “D:\Python3.6.5” with your installation directory.

D:\Python3.6.5
D:\Python3.6.5\DLLs
D:\Python3.6.5\lib
D:\Python3.6.5\lib\plat-win
D:\Python3.6.5\lib\site-packages

Or rename the python36._pth file

D:\Python3.6.5> ren python36._pth python36._pth.save

and set the PYTHONPATH environment variable for the current user.

setx PYTHONPATH "D:\Python3.6.5;D:\Python3.6.5\DLLs;D:\Python3.6.5\lib;D:\Python3.6.5\lib\plat-win;D:\Python3.6.5\lib\site-packages"

or for the whole system

setx /M PYTHONPATH "D:\Python3.6.5;D:\Python3.6.5\DLLs;D:\Python3.6.5\lib;D:\Python3.6.5\lib\plat-win;D:\Python3.6.5\lib\site-packages"
fzzylogic
  • 2,183
  • 1
  • 19
  • 25
sigmaxf
  • 7,998
  • 15
  • 65
  • 125
  • Did this on a portable windows `python-3.10.7` and it worked, althought used a relative folder in `c:\apps\python-3.10.7\python310._pth` settings file such as `.\Lib\site-packages` to add folder to a python syspath array. Run command `C:\apps\python-3.10.7\python.exe -m site` to list syspath settings. Example installing a cryptodome package `C:\apps\python-3.10.7\scripts\pip.exe install pycryptodomex` – Whome Sep 30 '22 at 11:15
  • Thank you! This was the important part that had me pull my hair out - `Any try to expand the variable by setting a PYTHONPATH variable are ignored. Root cause is that the embeddable zip file installation package contains a file python36._pth which overwrites all other possibilities to set the sys.path variable. sys.path contains all directories where python looks for modules. ` – Martin Melka Nov 15 '22 at 11:58
11

I ran into the same issue with the same version of Portable Python 3.2.5.1. The easy_install.py script located in App\Scripts\easy_install.py was broken for me too, due to some syntax error inside the script.

After many dead ends, I found https://winpython.github.io/. It picks up where Portable Python left off.

AaronDanielson
  • 2,230
  • 28
  • 29
  • Top Top Top. I have no clue why this does not show up first when you google for portable python – wuppi Jul 02 '15 at 10:14
  • 1
    "Hey, we're totally portable, just download our installer" - WinPython – sigmaxf Mar 20 '19 at 21:54
  • 1
    Odd approach, yet in their defence: "The WinPython folder can be moved to any location" - WinPython – Wouter Apr 10 '19 at 11:43
  • 1
    WinPython is several times bigger than Portable Python, though. I hesitate to say that it is 'bloated', but keep in mind that it comes with many, many modules. – jorvaor Nov 17 '22 at 08:55
2

Since you are using Portable Python, the best way to install modules is to use easy install. Go to your Portable Python folder directory: Portable Python 2.7.6.1.

Next open a command prompt in that location by Shift + Right Click.

Then type the following:

App\Scripts\easy_install.exe YourModuleNameHere

Example:

App\Scripts\easy_install.exe pyHook
adb16x
  • 658
  • 6
  • 24
  • 1
    For me, this worked to actually get pip and then get more stuff via pip with full dependencies, precompiled, etc... i.e.: `App\Scripts\easy_install.exe pip`, then e.g.: `App\Scripts\pip.exe install pywinauto` – akavel May 26 '15 at 14:21
  • 4
    I tried installing pip that way. I got the same error as the question. @akavel – Hadi Farah Jul 26 '18 at 11:21
0

If someone has problem using portable Python pip, those are my steps that make it work.

  1. Download portable Python from https://winpython.github.io.

  2. Run WinPython Command Prompt.exe and look for easy_install.exe.

  3. Enter easy_install.exe [package_you_want_install] in the WinPythonConsole.

Package will be installed in WinPython Python folder.

For those who want use Python e.g. in Node.js, electron project, you can only copy WinPython Python subfolder to project.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Sahaiel
  • 3
  • 1