如何使setuptools(或分发)从本地文件系统安装软件包 [英] How can I make setuptools (or distribute) install a package from the local file system

查看:129
本文介绍了如何使setuptools(或分发)从本地文件系统安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在已知位于本地文件系统上的setup.py中指定(可编辑)源依赖项?

Is it possible to specify (editable) source dependencies in setup.py that are known to reside on the local file system?

请考虑以下目录结构,所有目录结构都位于单个VCS存储库中:

Consider the following directory structure, all of which lives in a single VCS repository:

projects
  utils
    setup.py
    ...
  app1
     setup.py
     ... # app1 files depend on ../utils
  app2
     setup.py
     ... # app2 files depend on ../utils

给出以下命令:

cd projects
mkvirtualenv app1
pip install -e app1

我想安装app1的所有依赖项,包括"utils",这是一个可编辑的"依赖项.同样,如果我对ap​​p2做同样的事情.

I'd like to have all the dependencies for app1 installed, including "utils", which is an "editable" dependency. Likewise, if I did the same for app2.

我尝试使用install_requiresdependency_links中的file://... URL的所有不同组合都无济于事.我想使用像src+file://../utils这样的依赖关系链接URL,它会告诉setuptools包的源在文件系统上的此相对路径上.有办法吗?

I've tried playing with all different combinations of file://... URLs in install_requires and dependency_links to no avail. I'd like to use a dependency link URL like src+file://../utils, which would tell setuptools that the source for the package is on the file system at this relative path. Is there a way to do this?

推荐答案

我遇到了一个相同的问题,我需要依赖同级文件夹中的模块.在绊倒 https://caremad.io/2013/之后,我能够找到解决方案07/setup-vs-requirement/

I had an identical problem where I needed to depend on modules in a sibling folder. I was able to find a solution after stumbling upon https://caremad.io/2013/07/setup-vs-requirement/

我结束了requirements.txt文件,使其专门引用了我想要的文件,然后使用

I ended up requirements.txt to refer specifically to the file I wanted, and then installing everything with

pip install -r requirements.txt


requirements.txt

-e ../utils                                                                                                                                                                    
-e .

setup.py还有我所有的其他依赖项,包括utils.当pip尝试自行安装app1时,它意识到utils依赖关系已被填充,因此在安装其他要求时会通过它.

And setup.py has all my other dependencies, including utils. When pip tries to install app1 itself, it realizes that the utils dependency has already been filled, and so passes over it, while installing the other requirements.

这篇关于如何使setuptools(或分发)从本地文件系统安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆