0

I have just uninstalled some older python versions (3.9x, 3.10x) on windows 10 and reinstalled the latest python 3.10.7. My environment variables all reference the correct location for python, but when I run pip list I get a bunch of old packages when they should no longer be there. Since I uninstalled python with the intention to have a fresh installation, I don't want those old packages, but they are even still importable. If I run pip -v list, I see most of those (except the base packages that come with python) refer to ../appdata/roaming/python/python310/, instead of ..appdata/local/..., where Python is actually installed.

What can I do to clear this up? Sure I could pip uninstall them, but I don't know if this indicates a deeper issue and I am quite confused by it.

1 Answers1

-1

You get a ton of old packages because you didn't work with venvs sometimes! You can safely run this command to uninstall them all pip uninstall -y -r <(pip freeze) or either you can use your requirements.txt file to uninstall only specified libraries, as suggested in this thread.

Working with venvs fixes this exact problem. Every project will have its own environment with its own libraries to be installed. It may sound heavier (for example, if you have three projects that need requests, you will have to install requests three times) but you won't have any sort of version incompatibility since you can safely install different versions of the same package!

Always remember to set up the venv either using PyCharm or running these commands once you are in your folder:

python -m venv .
source venv/bin/activate
pip install -r requirements.txt

Either, if you will use Linux/Ubuntu, you can do apt install virtualenv, which also automatically creates a venv using this command:

virtualenv venv

Using venv also helps using a different Python version for each project meanwhile having them all installed! Here is how to change the version.

To exit a venv, just run the command deactivate! To understand if you're in a venv, you have to check whether (venv) is written before your host in the cmd or in the PyCharm terminal, like so:

NOT IN VENV:

marco@marco-Aspire-A515-51G:~

IN VENV:

(venv) marco@marco-Aspire-A515-51G:~
  • 1
    You are right, I sometimes forgot to activate my env while installing, but I'm still not understanding why these packages still exist AFTER I uninstalled all python installations. These are in `AppData/roaming/...`, but python installs to `AppData/Local/...`. This all started when I tried installing a package INSIDE a new conda environment with `pip install -U --user `, but found that it was installed to my standard pip. I ended up just fresh installing python, but now I'm facing this. – crabulus_maximus Oct 04 '22 at 09:49
  • If the remaining packages are outside `sys.path`, `pip` will not be able to find them, and thus also not uninstall them. – tripleee Oct 04 '22 at 09:50
  • because python and pip are separated! it's not an issue. just like maven and java, you can still uninstall java and keep every maven dependency in the .m2 folder. also don't forget windows is bad at uninstalling stuff ;) – Marco Frag Delle Monache Oct 04 '22 at 09:51
  • I'm sorry but I am still confused about what to do. I want to remove all traces of these old python installations including those packages that I somehow managed to get installed. But should I really just delete the folder from `.../roaming/`? Isn't it bad to manually do this? And if those packages are outside of `sys.path`, why can I still import them when running python? – crabulus_maximus Oct 04 '22 at 10:07
  • no, do not remove that folder manually! run the command to uninstall all dependencies in a row instead – Marco Frag Delle Monache Oct 04 '22 at 10:09
  • 1
    Ok I will do that, thanks for the help. But I am still confused! If I look in the installed python Lib/site-packages, there is nothing installed. So when I call pip in the terminal and see those packages, is this even the correct pip? `where pip` tells me it is in the newly installed python directory, but then it shouldn't see any packages. So it doesn't make sense to me. – crabulus_maximus Oct 04 '22 at 10:16
  • the magic of windows! this is one of the reasons why working on windows is painful – Marco Frag Delle Monache Oct 04 '22 at 10:19