便携式python - 无法安装pip

时间:2014-05-27 11:22:04

标签: pip portable-python

我正试着点击我的USB驱动器。按照this web sit上的说明,我下载了get-pip.py并运行python get-pip.pypython位于环境路径中)。不幸的是脚本通过错误。我已将日志文件上传到here。错误本身是:

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))

任何人都可以向我解释我做错了吗?

我使用的是便携式python 3.2.5.1,直到我尝试安装pip时,它才刚刚安装完毕。

4 个答案:

答案 0 :(得分:8)

我使用相同版本的Portable Python 3.2.5.1遇到了同样的问题。由于脚本中存在一些语法错误,位于App \ Scripts \ easy_install.py中的easy_install.py脚本也被破坏了。

经过多次死胡同,我找到了https://winpython.github.io/。它取决于Portable Python停止的地方。

答案 1 :(得分:2)

由于您使用的是Portable Python,因此安装模块的最佳方法是使用简易安装。 转到Portable Python文件夹目录:     Portable Python 2.7.6.1

然后按Shift + Right Click在该位置打开命令提示符。

然后输入以下内容:

App\Scripts\easy_install.exe YourModuleNameHere

示例:

App\Scripts\easy_install.exe pyHook

答案 2 :(得分:1)

好吧,如果使用可移植Python,是指Python.org提供的可嵌入zip文件,那么本指南解决了我的问题:https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/

以下是离线时的文字:

要在Windows上安装Python,请下载最新版本。在此示例中,Python 3.6.5。

将zip文件解压缩到目录中,例如D:\ python3.6.5。

要安装pip,请将最新版本的get-pip下载到pythons安装路径并开始安装。

> 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

如果您在代理后面,请添加–proxy开关

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

不幸的是,在默认配置下,您无法加载pip安装的任何模块,pip本身也无法加载。因为sys.path变量仅包含Python Zip文件和python可执行文件所在的python目录的路径。

>>> 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'

通过设置PYTHONPATH变量来扩展变量的任何尝试都将被忽略。根本原因是可嵌入的zip文件安装包中包含文件python36._pth,该文件会覆盖所有其他设置sys.path变量的可能性。 sys.path包含python查找模块的所有目录。

要设置sys.path变量,请打开_pth文件,并在和的文件中添加以下路径。用安装目录替换“ D:\ Python3.6.5”。

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

或重命名python36._pth文件

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

并为当前用户设置PYTHONPATH环境变量。

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"

或整个系统

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"

答案 3 :(得分:0)

如果有人在使用便携式Python pip时遇到问题,那么这些就是我使之起作用的步骤。

  1. https://winpython.github.io下载便携式Python。

  2. 运行WinPython Command Prompt.exe并寻找easy_install.exe

  3. easy_install.exe [package_you_want_install]中输入WinPythonConsole

程序包将安装在WinPython Python文件夹中。

对于想要使用Python的人,例如在Node.js电子项目中,您只能将WinPython Python子文件夹复制到项目中。