我猜您是开发子模块和项目的人,因为依赖项仍然在environment.yml
files.
选项 1:使用子模块的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
这不太理想,因为基本期望是您导入的库具有自己的依赖项。
选项 2:将依赖项放入各自的requirements.txt 文件中
仅当子模块依赖项可以通过 PyPi 安装时才适用pip
。首先将项目和子模块的依赖放入各自的requirements.txt
files.
然后重构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
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
这样你就可以忽略submodule_environment.yml
一起创建文件,然后使用单个命令创建项目环境。
$ conda env create --force -f project_environment.yml
如果您的submodule
依赖于conda
包。如果是这样,那么选项 1 是您的最佳选择。
选项 3:打包子模块(理想)
假设子模块没有 conda 依赖项,那么最好从子模块中创建一个单独的包。创建一个setup.py
并将所有依赖项放入install_requires
场地。这是一个模板,说明了如何setup.py https://gist.github.com/nitred/0764bfd72087946cab7c477395b24734#file-template_setup-py文件应该看起来像。
打包后,您可以执行以下操作:
- Install it locally using:
- Upload to github or bitbucket and install it using:
pip install git+https://github.com/username/submodule.git --upgrade
- Upload to github or bitbucket and add the following to
requirements.txt
or environment.yml
under pip
:
git+https://github.com/username/submodule.git#egg=submodule