Reconciling multiple python version, pip packages, and virtual environments

  Kiến thức lập trình

From Python updates I now have 3.9, 3.10, and 3.12 installed (not intentionally, I only needed the latest). I wasn’t using virtual environments and just installing packages globally with pip. I’m starting to take on some real projects so I’m working to set things up properly, but this is a mess. If I browse those python version directories, 3.10 has several packages in the site-packages sub folder. 3.9 has a couple generic ones, and 3.12 just has pip.

If I create a new virtual environment with venv it has about 20 packages that are not in any of the python directories above. With the virtual environment deactivated pip list doesn’t show anything other than pip. I have to usepython3.10 -m pip list to see what’s in 3.10, and can only see the ones added to the virtual environment if it’s active. In all cases I can still import and use them in code.

So, Questions:

  1. Where are those packages being added to the virtual environment coming from? and how do I remove them (globally, not in the venv) I’m not even sure what some of them are.

  2. How do I create a new virtual environment that doesn’t install any packages other than pip? I’ll install them from the requirements file. Isn’t that kind of the point of using them?

  3. Would I be better off just doing a clean install of Python, pip and everything related? If so, how do I make sure that all the old is gone before starting over? Is there a proper way to install Python so I don’t end up with future problems like this again?

Thanks!

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT