Uth*_*689 9 python git-submodules conda
考虑将具有依赖项的 Python 子模块导入具有自身依赖项的项目的情况。假设子模块有它的environment.yml文件,而项目本身有一个environment.yml文件。
有没有办法创建一个包含这两个环境规范的环境,如果是这样,您将如何进行?(或者是否有更好/更优选的方法来处理这种情况?)
我猜你是开发子模块和项目的人,因为依赖项仍在environment.yml文件中。
不幸的是,如果您的子模块依赖于conda包,这可能是您唯一的选择。
# First create the project environment
$ conda env create --force -f project_environment.yml
# Then update with submodule dependencies
$ conda env update -n project-env-name --file submodule_environment.yml
Run Code Online (Sandbox Code Playgroud)
这不太理想,因为基本期望是您导入的库带有自己的依赖项。
这仅适用于子模块依赖项可以通过pip. 首先将项目和子模块的依赖放入各自的requirements.txt文件中。
然后重组environment.yml文件以查看以下内容:
submodule_environment.yml
name: submodule-env-name
channels:
- defaults
dependencies:
- python=3.6.3 # no conda dependencies
- pip:
- -r requirements.txt # <--- submodule dependencies
Run Code Online (Sandbox Code Playgroud)
project_environment.yml
name: project-env-name
channels:
- defaults
dependencies:
- python=3.6.3
- pip:
- -r requirements.txt # <--- project dependencies
- -r project/submodule/requirements.txt # <--- submodule dependencies
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您可以submodule_environment.yml完全忽略该文件,然后使用单个命令创建项目环境。
$ conda env create --force -f project_environment.yml
Run Code Online (Sandbox Code Playgroud)
如果您submodule依赖conda包,这种方法将不起作用。如果是这样,则选项 1 是您的最佳选择。
假设子模块没有 conda 依赖项,那么最好从子模块中制作一个单独的包。创建一个setup.py并将所有依赖项放入该install_requires字段。这是setup.py文件的外观模板。
打包后,您可以执行以下操作:
pip install .pip install git+https://github.com/username/submodule.git --upgraderequirements.txt或environment.yml下面pip:
git+https://github.com/username/submodule.git#egg=submodule