3

How can I uninstall with pip one of the distributions which provide subpackages of a namespace package without breaking programs which only use subpackages of this namespace package from the remaining distributions?

I have 2 distributions (distribution{1,2}) providing 2 subpackages (package{1,2}) of a namespace package (namespace1):

distribution1/namespace1/__init__.py:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

distribution1/namespace1/package1/__init__.py:

from module1 import function1

distribution1/namespace1/package1/module1.py:

def function1():
    pass

distribution1/setup.py:

from setuptools import find_packages, setup

setup(
    name="distribution1",
    version="0.1",
    packages=find_packages())

distribution2/namespace1/__init__.py:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

distribution2/namespace1/package2/__init__.py:

from module2 import function2

distribution2/namespace1/package2/module2.py:

def function2():
    pass

distribution2/setup.py:

from setuptools import find_packages, setup

setup(
    name="distribution2",
    version="0.1",
    packages=find_packages())

And a test program:

main.py:

from namespace1.package1 import function1

function1()

When I install both distributions and uninstall one of them (distribution2), the example program fails:

% for i in distribution* ; do ( cd $i ; pip install . ) ; done   
Processing .../distribution1
Installing collected packages: distribution1
  Running setup.py install for distribution1
Successfully installed distribution1-0.1
Processing .../distribution2
Installing collected packages: distribution2
  Running setup.py install for distribution2
Successfully installed distribution2-0.1

% python main.py

% pip uninstall -y distribution2
Uninstalling distribution2-0.1:
  Successfully uninstalled distribution2-0.1

% python main.py                
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from namespace1.package1 import function1
ImportError: No module named namespace1.package1

It works when "pip install --egg ." was used in the distribution source folder. But since eggs are considered deprecated in favor of wheels, is there a solution without this "--egg" option?

Environment:

  • Python 2.7.9
  • setuptools 14.3.1
  • pip 6.1.1
  • wheel 0.24.0
Machavity
  • 30,841
  • 27
  • 92
  • 100
someone
  • 91
  • 2

0 Answers0