我正试着点击我的USB驱动器。按照this web sit的说明,我下载了get-pip.py
并运行python get-pip.py
(python
在环境路径中)。不幸的是脚本通过错误。我已将日志文件上传到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。
我使用相同版本的Portable Python 3.2.5.1遇到了同样的问题。由于脚本中存在一些语法错误,位于App \ Scripts \ easy_install.py中的easy_install.py脚本也被破坏了。
经过多次死胡同,我找到了https://winpython.github.io/。它取决于Portable Python停止的地方。
由于您使用的是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
好吧,如果使用Portable 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安装的任何模块,也可以自己。因为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"