Reputation: 1089
I did something very stupid. I was copying some self written packages to the python dist-packages folder, then decided to remove one of them again by just rewriting the cp
command to rm
. Now the dist-packages folder is gone. What do I do now? Can I download the normal contents of this folder from somewhere, or do I need to reinstall python completely. If so - is there something I need to be careful about?
The folder I removed is /usr/local/lib/python2.7
so not the one maintained by dpkg
and friends.
Upvotes: 5
Views: 5913
Reputation: 224
You can get a list of the packages installed by pip
with pip list
. Then you can run something like
pip list | tail -n+3 | cut -d' ' -f1 | xargs sudo pip install --force-reinstall
where
pip list
gives a list of the installed packages (as registered in the database),tail -n+3
skips the first two lines of output, which are just a heading,cut -d' ' -f1
removes the package version from each line andxargs sudo pip install --force-reinstall
reinstalls each package anew.The same thing happened to me, and this solution didn't entirely work out (some packages failed to install, for some reason) but it may work for you, or at least put you on the right path. (I realise this post is way to late, but this is for the people who run into this mishap in the future.)
Upvotes: 0
Reputation: 189689
The directory you removed is controlled and maintained by pip
. If you have a record of which packages you have installed with pip
, you can force it to reinstall them again.
If not, too late to learn to make backups; but this doesn't have to be a one-shot attempt -- reinstall the ones you know are missing, then live with the fact that you'll never know if you get an error because you forgot to reinstall a module, or because something is wrong with your code. By and by, you will discover a few more missing packages which you failed to remember the first time; just reinstall those as well as you discover them.
As an aside, using virtualenv
sounds like a superior solution for avoiding a situation where you need to muck with your system Python installation.
Upvotes: 2
Reputation: 942
I guess you are using a debian based distribution (ubuntu or similar). If so, you have to reinstall all python packages. You should be able to get most of them "automatically" by calling:
sudo dpkg --get-selections | grep -E "^python" | grep install | cut -f1 | xargs apt-get --reinstall -y install
Hope this helps. If you want to see which packages will be reinstalled, just call the first part of the piped commands:
sudo dpkg --get-selections | grep -E "^python"
Finally you should consider to use virtualenv or anaconda instead of installing or copying your own packages to dist-packages. If you don't want that, you could copy the packages to site-packages instead of dist-packages to seperate them from the distribution packages.
Upvotes: 14