How can I make setuptools (or distribute) install

2020-06-07 04:59发布

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

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

Given the following commands:

cd projects
mkvirtualenv app1
pip install -e app1

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.

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?

2条回答
唯我独甜
2楼-- · 2020-06-07 05:49

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/

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 .

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.

查看更多
冷血范
3楼-- · 2020-06-07 05:51

When I want to work with a set of projects interrelated, I install all of them using /setup.py develop.

If I mistakenly or later I want to make a pip-installed module editable, I clone the source, and do a python setup.py develop on it too, substituting the existing one.

Just to get sure, I erase the reference in the virtualenv's site-packages and the package itself.

查看更多
登录 后发表回答