Tag Archives: Packaging

Python packaging error

Let’s face it – the Python packaging is not necessary famous to be one of the best *cough*. But the following issue was purely my fault: I made a stupid error when generating a Python package. I had a constellation like this:

├── bin
│   └── collide.py
├── collide
│   ├── a_module.py
│   ├── another_module.py
│   └── __init__.py
├── README.txt
└── setup.py

I generated a package based on this calling python setup.py sdist. The collide.py script had an import statement to load a module stored in the collide folder. But as Python looks in the folder of the script for a module with such name first before checking other parts of the Python path it was reading the very same script again as module and raised an ImportError. It took me some time to figure out that this error occurs as the names of the script and the library folder are the same. I circumvent this by renaming the folder collide to collidelib and adapting the import statement accordingly. Memo to self – do not name the script in the bin folder of a package the same as the folder with the modules!