简体   繁体   中英

Python distutils - override old py implementation with .so C extension

The first draft of a package in my library was a foo.py file which I've now superseded with a Cython/C extension, a foo.so - however, distutils doesn't automagically realise that the old .py file is gone, so both sit in the site-packages directory after install (and who knows which is loaded when you use import ..)

Obviously I can manually remove the old files myself, but I don't want users of my library to have to care about this sort of thing.

What is the canonical / distutils / pythonic way to handle this? Is there some syntax like

from distutils import setup
setup(..., depricated=['path/to/foo.py'])

to indicate obsolete .py files to be removed from install directories on upgrade?

There is no uninstall command in distutils. Though pip can remove the old version automatically before installing a new one. Other installers also could provide an uninstall command.

Instruct your users to use pip if they are installing from source. Most binary formats such as rpm, deb, msi support uninstalling by default. btw, fpm provides an easy way to convert python packages.

You could use python -v to see what files are loaded for your module. .so might have a higher priority but you shouldn't rely on it in this case and remove the old version instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM