Python pip冻结集子目录

Python pip冻结集子目录,python,pip,git-submodules,requirements.txt,Python,Pip,Git Submodules,Requirements.txt,我有一个存储库,myBigRep,它包含一个子模块,mySmallRep。这个子模块是一个python项目,它有一个安装一些命令的setup.py脚本。要设置它,我运行: $ pip install --editable myBigRep/local/src/mySmallRep/ 就这样 现在我想在其他地方克隆mySmallRep,设置它的子模块并安装Python命令。因此,我首先冻结Python包: $ cd myBigRep $ pip freeze -e git+git@bitbuc

我有一个存储库,
myBigRep
,它包含一个子模块,
mySmallRep
。这个子模块是一个python项目,它有一个安装一些命令的
setup.py
脚本。要设置它,我运行:

$ pip install --editable myBigRep/local/src/mySmallRep/
就这样

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

$ cd myBigRep
$ pip freeze 
-e git+git@bitbucket.org:me/mySmallRep.git@d702f237b4c5449dffe5f224a8c361bf983566fc#egg=mySmallRep&subdirectory=../../../../local/src/mySmallRep

$ pip freeze > requirements.txt
$ git add requirements.txt
$ git commit -m "added requirements."
$ git push origin master
现在我克隆并设置所有内容:

$ 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
如果我删除requirement字段中的子模块,它也可以工作:

$ 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
有没有更好的办法解决这个问题