Python Forum
I don't understand pip and environments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't understand pip and environments
#1
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
Reply
#2
Take a look at The right and wrong way to set Python 3 as default on a Mac
Reply
#3
(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.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#4
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best practice on using virtual environments in Python bytecrunch 6 864 Feb-14-2024, 03:22 PM
Last Post: snippsat
  Virtual Environments - Organization (VS Code) JaysonWonder 11 1,869 Jan-26-2023, 11:34 PM
Last Post: Larz60+
  Keeping up with IDEs and Virtual Environments... bytecrunch 7 2,535 Sep-05-2022, 08:04 PM
Last Post: snippsat
  Use different Anaconda environments on Linux Mint and Spyder StaLLoNe_CoBRa 0 1,892 Jan-20-2021, 03:12 AM
Last Post: StaLLoNe_CoBRa
  pip and venv virtual environments soupworks 2 2,307 Dec-30-2020, 11:38 PM
Last Post: soupworks
  Virtual Environments pneveux 1 1,846 Apr-04-2019, 09:15 PM
Last Post: Larz60+
  Embedding, windows, and virtual environments mariofutire 0 3,059 Sep-14-2018, 10:30 AM
Last Post: mariofutire
  Different Virtual environments Pengwain 1 2,415 Jul-08-2018, 02:48 PM
Last Post: snippsat
  Installing blpapi in two different conda environments snicolaou 0 4,013 Jan-09-2018, 02:12 PM
Last Post: snicolaou

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020