Python: How to force overwriting of files when using setup.py install (distutil)
Asked Answered
L

3

43

I am using distutil to install my python code using

python setup.py install

I run into problems when I want to install an older branch of my code over a new one: setup.py install won't overwrite older files. A work around is touching (touch <filename>) all files so they are forced to be newer than those installed, but this is pretty ugly.

What I am looking for is an option to force overwriting of all files, eg. something like

python setup.py --force install

Any Ideas?

Lounge answered 2/10, 2013 at 9:27 Comment(0)
T
54

The Python developers had the same idea, they just put the option after the command:

python setup.py install --force

The distutils documentation doesn't mention the --force option specifically, but you can find it by using the --help option:

python setup.py --help install
Tollman answered 14/2, 2014 at 20:16 Comment(2)
Note, the --force overwrites, and does not remove files. I find I depend on pip uninstall <package> when I need to switch versions. Otherwise, you do not know what is lurking. If pip is not an option, then I think you have to manually remove /bin/<package-programs> and /lib/python/site-packages/<package>. Again, pip is your friend.Craniometry
The --force option does not appear to be documented nor functional in python3.Ruggles
C
5

Go to the setup.py directory and I simply use:

pip install .

It works for me.

Calysta answered 1/4, 2020 at 9:11 Comment(2)
It also works for me. It properly overwrites my files, even install --force didn't do that for some reason. setup.py seems to be properly executed and all my files are copied to where they should go.Confirmand
https://mcmap.net/q/144361/-difference-between-39-python-setup-py-install-39-and-39-pip-install-39 "So basically, use pip. It only offers improvements"Confirmand
H
0

In my case, I have to remove the build and dist folders

rm -rf build
rm -rf dist
python3 setup.py install
Homegrown answered 29/11, 2022 at 19:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.