Search code examples
pythonpackagingsetup.py

Why is setup.py installing old files?


I'm working on a python module for a larger system. I did a setup.py package for installing it in the main module. It worked correctly, but then i did some changes to my module, mainly modified the names of the py files, and reorganize a bunch of classes.

Then I updated the version of the module, uninstall the old one with pip, and install the new version using python setup.py install and when i try to import in ipython found that i got the older, erased module.

Found it quite odd and checked my virtualenv lib folder and found both versions of the module, with the old classes structure and the new one. And both usable, as I imported both in ipython and tested it.

It doesn't raises any problem, as I can simply use the newest version, but is confusing. Any idea why this behaviour?


Solution

  • If you don't install with pip, you can't uninstall with pip, so you never actually uninstalled the old version. python setup.py install will install different versions, but typically they install on top of the old versions (except for the .egg-info file or directory). You don't say how exactly the two versions were living side-by-side, because setup.py (or pip) won't rename site-packages/my_module to my_module_v1, for example. I assume that you changed the directory structure and .py file names enough that the two versions could coexist in the same parent directory, so in IPython you could run from my_module import OldClassName and from my_module import NewClassName.