最近买了一台新的 Mac 并准备将它用于 Python 和 iOS 开发。 Python 运行良好——尤其是在安装 Xcode、macports 和 Apple 的命令行工具之前,pip'ing git repos 有很多 requirements.txt 依赖项。
现在 pip 可以很好地用于单独安装(例如,pip install twilio),但是每当我针对 requirements.txt 文件运行 pip 时,它都会失败(无论是否使用 sudo):
pip install ./requirements.txt
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 225, in run
InstallRequirement.from_line(name, None))
File "/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 118, in from_line
return cls(req, comes_from, url=url)
File "/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 43, in __init__
req = pkg_resources.Requirement.parse(req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2510, in parse
reqs = list(parse_requirements(s))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2436, in parse_requirements
line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2404, in scan_list
raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', './requirements.txt', 'at', '/requirements.txt')
我的
$PATH
值是/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
这看起来与“OS X 10.8 升级后 Python pip 损坏”线程不同。我想知道 macports 是否在查看
/System/Libary
和 ~/Library
之间产生了冲突。有任何想法吗?
最佳答案
如果要通过需求文件安装软件包,则需要 --requirement/-r
选项:
$ pip install -r requirements.txt
关于安装 OS X 10.8 macports 后,python pip 无法处理 requirements.txt,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14007785/