Python Forum

Full Version: I don't understand pip and environments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm completely confused... partly because I decided to buy a Mac!

I play about with Python and Scikit-learn from time to time mostly on a Linux desktop. It was dead easy to install modules... "zypper install numpy" etc.

Then I bought a MacBook. Python 3.8 was already installed and I found I had to use commands like "python3 -m pip install -U matplotlib". I've no idea what -m and -U is for but that's what I found on the internet. If I check to see what is installed "pip list" or "python3 pip list" it tells me pip isn't installed.

I've no idea why but I decided to go the the Python website, download and install 3.10 and now when I use 3.10 in vscode none of the modules load. Apparently it's something to do with having them installed in a different environment?

What I really want to do now is work out how to uninstall 3.10 and stick with 3.8 simply for simplicity but Mac seems to make that an elusive task too!

A bit of a rant because I regret buying a Mac instead of something I could put Linux on but I would love to know how pip works!

Thank you for any help
(Jul-31-2022, 09:14 AM)snakes Wrote: [ -> ]I've no idea what -m and -U is for...

Output:
-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script. -U, --upgrade Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.
Thank you for the replies.

I managed to uninstall Python 3.10 from the Mac and although pip doesn't work pip3 does. It kind of did before I uninstalled 3.10 but "pip3 list" was empty. Now it's full. I think that thing is going to be on eBay soon! No more coding on the Macbook.

Back to Linux though... I don't seem to have Python2 installed and in VSCode I only have the option for 3.6.15. Both "pip -V" and "pip3 -V" return "pip 20.0.2 from /usr/lib/python3.6/site-packages/pip (python 3.6)". Does this mean it doesn't matter which one I use or is there a difference?

I still don't understand virtual environments though. I'm going through all these motions now because I've recently reinstalled my OS so I'm using a clean slate and I hate blasting lots of install code into the terminal until something works. I like to keep my OS as lean as possible.

An example of why I'm confused... I wrote some code that uses tkcalendar. It wouldn't run because I don't have the module installed. "pip install tkcalendar" and then it worked. I then uninstalled tkcalendar and it didn't work, obviously. I then setup a virtual environment in the directory my .py file is in, activated the environment and installed tkcalendar again. ...fired up VSCode, ran the code and "ModuleNotFoundError: No module named 'ttkthemes'". So I still don't understand how they work.

How do you make use of the environment?

Also, if I get my head around how to use modules installed in an environment I guess installing different versions of Python will work the same?

Sorry for the elementary questions! I just glazed over this stuff when it popped up in a book I was reading but I'm beginning to realise it's important!

EDIT: Got it! The virtual environment is selectible in VSCode. Sorry!