pip冻结集子目录

2024-04-19 00:20:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个存储库myBigRep,它包含一个子模块mySmallRep。{cd3>安装一个包含子命令的python项目。要设置它,我运行:

$ pip install --editable myBigRep/local/src/mySmallRep/

就这样。在

现在我想把mySmallRep克隆到其他地方,设置它的子模块并安装Python命令。所以我首先冻结Python包:

^{pr2}$

现在我克隆并设置所有内容:

$ cd
$ git clone git@bitbucket.org:me/myBigRep.git myBigRepClone
$ cd myBigRepClone
$ git submodule init && git submodule update
$ git submodule foreach git pull origin master
$ pip install --requirement requirements.txt
Obtaining mySmallRep from git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep&subdirectory=../../../../local/src/mySmallRep (from -r requ.txt (line 2))
  Skipping because already up-to-date.
    Error [Errno 2] No such file or directory: '/home/me/myBigRepClone/src/mySmallRep/../../../../local/src/mySmallRep' while executing command python setup.py egg_info
Exception:
Traceback (most recent call last):
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
    wb.build(autobuilding=True)
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/req/req_set.py", line 518, in _prepare_file
    abstract_dist.prep_for_dist()
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/req/req_install.py", line 439, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/site-packages/pip/utils/__init__.py", line 667, in call_subprocess
    cwd=cwd, env=env)
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/home/me/myBigRepClone/local/miniconda3/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory: '/home/me/myBigRepClone/src/mySmallRep/../../../../local/src/mySmallRep'

很明显最后一条路是错的。但如果我手动执行命令,它会起作用:

$ pip install -e git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep&subdirectory=../../../../local/src/mySmallRep
[1] 19227
Obtaining mySmallRep from git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep
  Skipping because already up-to-date.
Requirement already satisfied: click in ./local/miniconda3/lib/python2.7/site-packages (from mySmallRep)
Installing collected packages: mySmallRep
  Running setup.py develop for mySmallRep
Successfully installed mySmallRep

如果我删除需求字段中的子模块,它也会起作用:

$ pip uninstall mySmallRep -y
Uninstalling mySmallRep-0.1:
  Successfully uninstalled mySmallRep-0.1

$ cat requirements.txt 
-e git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep&subdirectory=../../../../local/src/mySmallRep

$ cat requirements.txt | sed 's/&subdirectory.*//g'
-e git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep

$ sed 's/&subdirectory.*//g' -i requirements.txt

$ pip install --requirement requirements.txt 
Obtaining mySmallRep from git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep (from -r requirements.txt (line 1))
  Skipping because already up-to-date.
Requirement already satisfied: click in ./local/miniconda3/lib/python2.7/site-packages (from mySmallRep->-r requirements.txt (line 1))
Installing collected packages: mySmallRep
  Running setup.py develop for mySmallRep
Successfully installed mySmallRep

为什么把子目录放在第一位?在

为什么处理requirements.txt文件中的子目录不起作用,而如果是手动安装的话?在

在自动化上下文中,我需要完美地冻结包并从requirements.txt文件安装它们。我发现的一个肮脏的解决办法是在我的脚本中写下以下内容:

$ pip freeze | sed 's/&subdirectory.*//g' > requirements.txt

有没有更好的方法来解决这个问题?在


Tags: pipinpygittxthomelibpackages