问题描述
我们的项目具有以下高级目录结构*
We have project with the following high-level directory structure*
./datascience/
├── core
│ └── setup.py
├── notebooks
│ └── Pipfile
└── web
└── Pipfile
core
程序包是一个库.它是notebooks
和web
应用程序的依赖项.
The core
package is a library. It's a dependency of both the notebooks
and web
applications.
core
程序包,是图书馆,其依赖项在setup.py
The core
package, being a library, has its dependencies specified in setup.py
import setuptools
setuptools.setup(
install_requires=[
'some-dependency',
'another-dependency'
]
)
web
和notebooks
应用程序正在使用 pipenv 进行依赖项管理.它们的依赖关系在Pipfile
中指定.
The web
and notebooks
applications are using pipenv for dependency management. Their dependencies are specified in a Pipfile
.
例如,下面是在web/Pipfile
中指定web
依赖项的方式:
For example, here's how the web
dependencies are specified in web/Pipfile
:
[packages]
datascience-core = {path = "./../core"}
flask = "~= 1.0"
请注意core
依赖项是本地依赖项,因此是相对路径.
Notice how the core
dependency is a local dependency, hence the relative path.
从web
或notebooks
目录内部执行pipenv install
并不会像我期望的那样安装core
库的依赖项!
Doing a pipenv install
from inside the the web
or notebooks
directory, does not install the dependencies of the core
library as I expected!
我还尝试对core
使用Pipfile
,希望pipenv可以在其图形中找到它并下载所有嵌套的依赖项.但事实并非如此.
I also tried using a Pipfile
for core
, hoping that pipenv would pick it up in its graph and download all the nested dependencies. But it doesn't.
pipenv正在为web
或notebooks
应用程序安装依赖项时,如何自动安装core
应用程序的依赖项?
How can dependencies of the core
app be installed automatically when pipenv is installing dependencies for the web
or notebooks
app?
推荐答案
由于在pipenv问题线程中的此注释,找到了一个解决方案: https://github.com/pypa/pipenv/issues/209#issuecomment-337409290
Found a solution thanks to this comment in a pipenv issue thread: https://github.com/pypa/pipenv/issues/209#issuecomment-337409290
我继续在setup.py
中列出core
的依赖项.
I've continued listing the core
's dependencies in setup.py
.
我将web
和notebook
应用程序更改为使用core
软件包的可编辑安装.
这是通过在web
和notebooks
目录中运行以下命令来完成的:
I've changed the web
and notebook
apps to use an editable installation of the core
package.
This was done by running the following in both the web
and notebooks
directory:
pipenv install --editable ../core
它产生了差异
[packages]
- datascience-core = {path = "./../core"}
+ datascience-core = {editable = true,path = "./../core"}
现在从web
和notebooks
目录运行pipenv install
会导致core
软件包及其依赖项的安装!
Now running pipenv install
from the web
and notebooks
directory results in the installation of the core
package and its dependencies!
它还解决了另一个非常烦人的问题,每次core
发生变化时,都必须pipenv install
.现在,它无需重新安装本地软件包就可以进行开发更改!
It also solved another very annoying problem, which was having to pipenv install
every time there was a change in core
. Now it picks up development changes without having to re-install the local package!
这篇关于使用Pipenv安装本地依赖项的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!