-3

been trying to do this for the last 3 hours with NO SUCESS at all.

I want to install Python modules in VS Code on a MAC BOOK PRO.

I enter the command pip3 install matplotlib or pip3 install keyboard AND NOTHING WORKS. This seems like the worst IDE on the planet. I keep getting the message in the terminal window of No module named 'matplotlib' when I clearly HAVE downloaded it. I'm enclosing a screen shot here.screenshot when not working

ALSO - I Do NOT want to run in a virtual environment. I want to use the modules in any program I run. I cannot program without getting round this issue so any help would be greatly appreciated ! I am very new to Python in VS code.

3 Answers3

0

Managing Python versions has become somewhat of a quagmire (and some would say that's generous).

In the same way that your system will search through the folders in $PATH looking for binaries, python will search through the folders in $PYTHON_PATH looking for modules. So you need to know:

  1. where does pip3 install your modules?
  2. is that in echo $PYTHON_PATH?

More info here:

Failing that, pyenv is a tool that help manage multiple python versions in a system (I just started dabbling with this last night myself). Basically you would do something like:

  1. install pyenv
  2. use pyenv to (e.g.) pyenv install 3.9.6
  3. define your global python versions pyenv global 3.9.6

One can install pyenv from Homebrew: https://github.com/pyenv/pyenv#homebrew-on-macos

Adam Smooch
  • 1,167
  • 1
  • 12
  • 27
0

Try running which python3 in the terminal. In mac the default python is installed in /Library/Frameworks/Python.framework/Versions/3.9/bin/python3. So if you install package with pip3 it will be installed in Location: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-package. And according to your posted image you are running your program with /usr/bin/python3 which is unable to find the installed packages.enter image description here

Dipto Mondal
  • 624
  • 1
  • 4
  • 14
0

Python works pretty bad for beginners IMHO, especially when people usually have no idea that both Python 2 and 3 are there (and even more minor versions on the same machines for whatever reasons).

Learn the python version being used

For your current folder opened in VSCode, 3.8.2 64 bit is used and shown in the status bar, so click it and check the popup list at top to learn what are the Python executable paths available on this machine.

You should choose /usr/bin/python3 from the list, as that's usually the default many people is using right now.

After that configuration, VSCode sticks to that executable to locate all modules and so on.

Install modules

As now you know the path of Python executable, installing a module are simply,

/usr/bin/python3 -m pip install some.module

Calling pip in this way avoid all the mess with other approaches (as they can simply install the module for another Python executable under your nose).

This should be enough to get you started on your Python journey, but far from enough to make sure you can write scripts and debug them.

Ideally, find a teacher/mentor or just someone with more Python experience than you to guide you through. Then you don't need to waste time on the tiny little things.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Many thanks for this, yes it's working now - but run into many more problems as the keyboard module will not run if not administrator - but thanks for your reply! – Adrian Salt Jul 23 '21 at 16:00