我有一个项目文件夹,它是一个git存储库(有一个.git文件夹).当我使用命令pip freeze时,pip尝试使用git.但是,我的系统上没有安装git,因此会导致错误:
(env) PS C:\Users\eclaird\work\myproject> pip freeze
Cannot find command 'git'
Storing complete log in C:\Users\eclaird\pip\pip.log
(env) PS C:\Users\eclaird\work\myproject>
pip.log:
------------------------------------------------------------
C:\Users\eclaird\work\env\Scripts\pip-script.py run on 01/09/14 11:54:42
Cannot find command 'git'
Exception information:
Traceback (most recent call last):
File "C:\Users\eclaird\work\env\lib\site-packages\pip\basecommand.py", line 134, in main
status = self.run(options, args)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\commands\freeze.py", line 73, in run
req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\__init__.py", line 180, in from_dist
req = get_src_requirement(dist, location, find_tags)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\vcs\__init__.py", line 249, in get_src_requirement
return version_control().get_src_requirement(dist, location, find_tags)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\vcs\git.py", line 151, in get_src_requirement
repo = self.get_url(location)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\vcs\git.py", line 122, in get_url
[self.cmd, 'config', 'remote.origin.url'],
File "C:\Users\eclaird\work\env\lib\site-packages\pip\vcs\__init__.py", line 110, in cmd
command = find_command(self.name)
File "C:\Users\eclaird\work\env\lib\site-packages\pip\util.py", line 108, in find_command
raise BadCommand('Cannot find command %r' % cmd)
BadCommand: Cannot find command 'git'
有没有办法在pip中禁用git集成?
(pip 1.4.1,
Python 2.7.6)
最佳答案 很不幸的是,不行.没有配置选项来启用/禁用后端.
通过挖掘代码找到的详细信息:
Git模块始终注册:在pip/install.py中,导入git module.在它结束时,它会自己注册,因此只要在’git.Git’中声明的一个方案与依赖的url匹配,就会被查询.
schemes = ('git', 'git+http', 'git+https', 'git+ssh', 'git+git', 'git+file')
没有处理异常Funnily,冻结预计在确定要冻结的依赖URL时可能会发生错误.摘自pip.FrozenRequirement:
try:
req = get_src_requirement(dist, location, find_tags)
except InstallationError:
logger.warn("Error when trying to get requirement for VCS system %s, falling back to uneditable format" % ex)
InstallationError inherits from PipError.不幸的是,引发了类型”BadCommand’的例外,它继承自’aptError’.
所以,除了黑客攻击:你无能为力.如果你需要这个,你需要安装git,破解源代码或模拟git可执行文件.如果你选择后者,对于初学者你需要伪造’git config remote.origin.url’,这在pip.vcs.git.Git.get_url被称为(并失败).
希望有所帮助,即使它不是肯定的. 😉