Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip install with and without "-e" option changes package import behavior #463

Closed
ghost opened this issue Nov 20, 2015 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Nov 20, 2015

Originally reported by: roopeshvaddepally (Bitbucket: roopeshvaddepally, GitHub: roopeshvaddepally)


When multiple modules imported from different directories to form a package, import behavior changes with "-e" option when installed with "pip install" command.

Ignore the way it's organized (I'm packaging an existing library).

pip install -e does not recognize the package_dir package names when installed, but pip install does.

Setup the Python Package and add setup.py

(testpackages)19:55:01 [rvaddepally@system-tc8 ~]
> which python
~/.pyenv/versions/testpackages/bin/python
(testpackages)19:55:07 [rvaddepally@system-tc8 ~]
> python --version
Python 3.4.3
> mkdir !$
mkdir testpack

(testpackages)19:57:56 [rvaddepally@system-tc8 ~/src/testpack]
> mkdir -p src/pack_a/mod_a src/pack_a/mod_b src/dir_x/pack_b/mod_x src/dir_x/pack_b/mod_y
(testpackages)20:00:27 [rvaddepally@system-tc8 ~/src/testpack]
> tree .
.
└── src
    ├── dir_x
    │   └── pack_b
    │       ├── mod_x
    │       └── mod_y
    └── pack_a
        ├── mod_a
        └── mod_b

8 directories, 0 files

(testpackages)20:00:30 [rvaddepally@system-tc8 ~/src/testpack]
> touch src/dir_x/pack_b/__init__.py src/dir_x/pack_b/mod_x/__init__.py src/dir_x/pack_b/mod_y/__init__.py src/pack_a/__init__.py src/pack_a/mod_a/__init__.py src/pack_a/mod_b/__init__.py
(testpackages)20:16:28 [rvaddepally@system-tc8 ~/src/testpack]
> tree .
.
├── setup.py
└── src
    ├── dir_x
    │   └── pack_b
    │       ├── __init__.py
    │       ├── mod_x
    │       │   └── __init__.py
    │       └── mod_y
    │           └── __init__.py
    └── pack_a
        ├── __init__.py
        ├── mod_a
        │   └── __init__.py
        └── mod_b
            └── __init__.py

8 directories, 7 files


# add this to setup.py
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
from setuptools import setup, find_packages


my_packages = (find_packages('src', include=['pack_a*']) +
               find_packages('src/dir_x', include=['pack_b*']))

setup(
    name='testpack',
    version='0.0.1',
    packages=my_packages,
    package_dir={
        'pack_a': 'src/pack_a',
        'pack_b': 'src/dir_x/pack_b',
    },
    install_requires=[],
    author='my name',
    description='',
    license='XYZ',
)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Verify package is not installed

(testpackages)20:23:08 [rvaddepally@system-tc8 ~/src/testpack]
> pip freeze
decorator==4.0.4
ipython==4.0.0
ipython-genutils==0.1.0
path.py==8.1.2
pexpect==4.0.1
pickleshare==0.5
ptyprocess==0.5
simplegeneric==0.8.1
traitlets==4.0.0
wheel==0.24.0
(testpackages)20:23:13 [rvaddepally@system-tc8 ~/src/testpack]
> python -c "import testpack"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'testpack'

pip install the package and verify modules are available

(testpackages)20:24:02 [rvaddepally@system-tc8 ~/src/testpack]
> pip install .
Processing /auto/home.nas01a/rvaddepally/src/testpack
Installing collected packages: testpack
  Running setup.py install for testpack
Successfully installed testpack-0.0.1

(testpackages)20:25:01 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from pack_a import mod_a, mod_b'
(testpackages)20:25:43 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from pack_b import mod_x, mod_y'
(testpackages)20:26:00 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from pack_b import mod_z'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'mod_z'

Uninstall

> pip uninstall testpack
Uninstalling testpack-0.0.1:
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/mod_a/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/mod_a/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/mod_b/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_a/mod_b/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/mod_x/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/mod_x/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/mod_y/__init__.py
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/pack_b/mod_y/__pycache__/__init__.cpython-34.pyc
  /auto/home.nas01a/rvaddepally/.pyenv/versions/testpackages/lib/python3.4/site-packages/testpack-0.0.1-py3.4.egg-info
Proceed (y/n)? y
  Successfully uninstalled testpack-0.0.1

pip install -e the package and verify modules are available, but not with pack_a and pack_b package names

(testpackages)20:27:04 [rvaddepally@system-tc8 ~/src/testpack]
> pip install -e .
Obtaining file:///auto/home.nas01a/rvaddepally/src/testpack
Installing collected packages: testpack
  Running setup.py develop for testpack
Successfully installed testpack


(testpackages)20:28:26 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from pack_a import mod_a, mod_b'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'pack_a'

(testpackages)20:28:33 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from src.pack_a import mod_a, mod_b'

(testpackages)20:28:43 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from pack_b import mod_x, mod_y'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'pack_b'

(testpackages)20:28:55 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from src.dir_x.pack_b import mod_x, mod_y'

(testpackages)20:29:18 [rvaddepally@system-tc8 ~/src/testpack]
> python -c 'from src.dir_x.pack_b import mod_z'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'mod_z'

@ghost
Copy link
Author

ghost commented Nov 20, 2015

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Duplicate of #230.

@ghost ghost added major bug labels Mar 29, 2016
@ghost ghost closed this as completed Mar 29, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants