便携式 python - 无法安装 pip

2024-04-21

我正在尝试在我的 USB 驱动器上获取 pip。按照以下说明进行操作这个网站 https://pip.pypa.io/en/latest/installing.html, 我下载了get-pip.py并运行python get-pip.py (python位于环境路径中)。不幸的是脚本出现了错误。我已将日志文件上传到here https://drive.google.com/file/d/0B3DAJEXg_yQhaHAtVWZUMGRJSzQ/edit?usp=sharing。错误本身是:

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 之前,它是全新的安装版本。


好的,如果“便携式 Python”指的是 Python.org 提供的可嵌入 zip 文件,那么本指南解决了我的问题:https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/ 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 https://bootstrap.pypa.io/get-pip.py到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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

便携式 python - 无法安装 pip 的相关文章

随机推荐