0

I read the Packing Projects Documentation, searched this question here in stackoverflow but found nothing similar, and my low experience using third-party library tells me it's not possible. The closest I got was pip install from git repo branch

Let's suppose I have two python libraries in PyPI, each one with it's own repository and I can install them using the pip:

pip install mylib-foo
pip install mylib-bar

currently I can import them using

import mylibfoo
import mylibbar

Question 1: Is there a way to import them using the code below, without merging the repositories and create only one PyPI project?

import mylib.foo
import mylib.bar

Merging the repositories I mean just like numpy does: We can import numpy.linalg and numpy.random, but they both are in the same repository/project.

Question 2: Now let's suppose that we have only one PyPI project, in only one repository (just like numpy does). Is there a way to install only a part of the mylib library?

pip install mylib-foo  # Install only mylib.foo
pip install mylib-bar  # Install only mylib.bar
pip install mylib  # Install both

So, if someone did only pip install mylib-foo and tries to import mylib.bar, he receives an error.

Carlos Adir
  • 452
  • 3
  • 9
  • 3
    You're looking for [Namespace packages](https://setuptools.pypa.io/en/latest/userguide/package_discovery.html). See https://stackoverflow.com/search?q=%5Bsetuptools%5D+namespace+packages Also see my examples: https://stackoverflow.com/a/50282888/7976758 – phd Nov 04 '21 at 15:33
  • You could also create a folder called *mylib* with an __init__.py. Inside the init, you can import the modules as so: ```import mylibfoo as foo \n import mylibbar as bar```. Now when you write ```import mylib.foo```, *mylib* is referring to the directory you created. For enforcing different modules to be installed as a bundle, I would look into using the tool [pipenv](https://docs.pipenv.org/). – Jeff Gruenbaum Nov 04 '21 at 17:25

0 Answers0