加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – pip尝试在未安装git时使用git

发布时间:2020-12-20 11:32:42 所属栏目:Python 来源:网络整理
导读:我有一个项目文件夹,它是一个git存储库(有一个.git文件夹).当我使用命令pip freeze时,pip尝试使用git.但是,我的系统上没有安装git,因此会导致错误: (env) PS C:Userseclairdworkmyproject pip freezeCannot find command 'git'Storing complete log in
我有一个项目文件夹,它是一个git存储库(有一个.git文件夹).当我使用命令pip freeze时,pip尝试使用git.但是,我的系统上没有安装git,因此会导致错误:

(env) PS C:Userseclairdworkmyproject> pip freeze
Cannot find command 'git'
Storing complete log in C:Userseclairdpippip.log
(env) PS C:Userseclairdworkmyproject>

pip.log:

------------------------------------------------------------
C:UserseclairdworkenvScriptspip-script.py run on 01/09/14 11:54:42
Cannot find command 'git'
Exception information:
Traceback (most recent call last):
  File "C:Userseclairdworkenvlibsite-packagespipbasecommand.py",line 134,in main
    status = self.run(options,args)
  File "C:Userseclairdworkenvlibsite-packagespipcommandsfreeze.py",line 73,in run
    req = pip.FrozenRequirement.from_dist(dist,dependency_links,find_tags=find_tags)
  File "C:Userseclairdworkenvlibsite-packagespip__init__.py",line 180,in from_dist
    req = get_src_requirement(dist,location,find_tags)
  File "C:Userseclairdworkenvlibsite-packagespipvcs__init__.py",line 249,in get_src_requirement
    return version_control().get_src_requirement(dist,find_tags)
  File "C:Userseclairdworkenvlibsite-packagespipvcsgit.py",line 151,in get_src_requirement
    repo = self.get_url(location)
  File "C:Userseclairdworkenvlibsite-packagespipvcsgit.py",line 122,in get_url
    [self.cmd,'config','remote.origin.url'],File "C:Userseclairdworkenvlibsite-packagespipvcs__init__.py",line 110,in cmd
    command = find_command(self.name)
  File "C:Userseclairdworkenvlibsite-packagespiputil.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,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被称为(并失败).

希望有所帮助,即使它不是肯定的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读