3

I wrote a package. It has subdirectory called keynames containing key names assigned to values they are represented in stdin. When I ran python setup.py sdist, keynames was added to source distribution:

running sdist
running egg_info
writing getchlib.egg-info/PKG-INFO
writing dependency_links to getchlib.egg-info/dependency_links.txt
writing top-level names to getchlib.egg-info/top_level.txt
reading manifest file 'getchlib.egg-info/SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'getchlib.egg-info/SOURCES.txt'
running check
creating getchlib-1.0.7
creating getchlib-1.0.7/getchlib
creating getchlib-1.0.7/getchlib.egg-info
creating getchlib-1.0.7/getchlib/keynames
copying files to getchlib-1.0.7...
copying LICENSE -> getchlib-1.0.7
copying README.md -> getchlib-1.0.7
copying setup.py -> getchlib-1.0.7
copying getchlib/__init__.py -> getchlib-1.0.7/getchlib
copying getchlib/ctrl.py -> getchlib-1.0.7/getchlib
copying getchlib/decorators.py -> getchlib-1.0.7/getchlib
copying getchlib/getkey.py -> getchlib-1.0.7/getchlib
copying getchlib/hotkey.py -> getchlib-1.0.7/getchlib
copying getchlib/pressed.py -> getchlib-1.0.7/getchlib
copying getchlib/printer.py -> getchlib-1.0.7/getchlib
copying getchlib/term.py -> getchlib-1.0.7/getchlib
copying getchlib/unix.py -> getchlib-1.0.7/getchlib
copying getchlib/windows.py -> getchlib-1.0.7/getchlib
copying getchlib.egg-info/PKG-INFO -> getchlib-1.0.7/getchlib.egg-info
copying getchlib.egg-info/SOURCES.txt -> getchlib-1.0.7/getchlib.egg-info
copying getchlib.egg-info/dependency_links.txt -> getchlib-1.0.7/getchlib.egg-info
copying getchlib.egg-info/top_level.txt -> getchlib-1.0.7/getchlib.egg-info
copying getchlib/keynames/__init__.py -> getchlib-1.0.7/getchlib/keynames
copying getchlib/keynames/raw.py -> getchlib-1.0.7/getchlib/keynames
Writing getchlib-1.0.7/setup.cfg
Creating tar archive
removing 'getchlib-1.0.7' (and everything under it)

In getchlib-1.0.7.tar.gz is that directory. It's also in source distribution at PyPI. But when I called pip install getchlib, ~/.local/lib/python3.9/site-packages/getchlib did not contain keynames subdirectory:

[adam@gastan site-packages]$ ls ~/.local/lib/python3.9/site-packages/getchlib -l
total 44
-rw-r--r-- 1 adam adam 1137 Dec  9 21:07 ctrl.py
-rw-r--r-- 1 adam adam  205 Dec  9 21:07 decorators.py
-rw-r--r-- 1 adam adam  294 Dec  9 21:07 getkey.py
-rw-r--r-- 1 adam adam 1976 Dec  9 21:07 hotkey.py
-rw-r--r-- 1 adam adam   68 Dec  9 21:07 __init__.py
-rw-r--r-- 1 adam adam  231 Dec  9 21:07 pressed.py
-rw-r--r-- 1 adam adam  112 Dec  9 21:07 printer.py
drwxr-xr-x 2 adam adam 4096 Dec  9 21:07 __pycache__
-rw-r--r-- 1 adam adam  449 Dec  9 21:07 term.py
-rw-r--r-- 1 adam adam 2350 Dec  9 21:07 unix.py
-rw-r--r-- 1 adam adam  429 Dec  9 21:07 windows.py

And therefore, import getchlib failed with ImportError:

[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import getchlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/adam/.local/lib/python3.9/site-packages/getchlib/__init__.py", line 3, in <module>
    from . import keynames
ImportError: cannot import name 'keynames' from partially initialized module 'getchlib' (most likely due to a circular import) (/home/adam/.local/lib/python3.9/site-packages/getchlib/__init__.py)
Adam Jenča
  • 582
  • 7
  • 20
  • 1
    https://stackoverflow.com/a/15368107/7976758 – phd Dec 09 '21 at 20:27
  • Pretty non-intuittive behavior.... I added the file in MANIFEST and also in egg-info/SOURCES.txt and I have to add it also to setup.py . Could be puzzling for beginner to packaging(as me). – Adam Jenča Dec 10 '21 at 06:31

0 Answers0