Here the answer that worked, which is basically what has been explained in the comments of the question. However, I thought it would be useful to have it explained as a clear and well structured answer.
As highlighted, the problem was that I was not using the interpreter that pip was installing for.
The command which shows where pip was installing the modules:
$ which -a pip
/usr/local/bin/pip
and where the different python versions were located:
$ which -a python
/usr/bin/python
/usr/local/bin/python
That is, my system/default python was
/usr/bin/python
while pip was installing for
/usr/local/bin/python
Therefore, I could not import anything I installed when I just typed python, because the /usr/bin/python interpreter was the one started.
Solution
Install pip again specifying the destination of the modules that will be installed. This must be the destination for the system/default python.
This has been done in two steps:
Downloding
get-pip.pyfrom bootstrap.pypa.io/get-pip.py. (You may need to use the deprecated one for Python 2: bootstrap.pypa.io/2.7/get-pip.py)Installing it with the following command
sudo /usr/bin/python get-pip.py
Note that without the sudo I got an error and was not able to install pip.
Here the answer that worked, which is basically what has been explained in the comments of the question. However, I thought it would be useful to have it explained as a clear and well structured answer.
As highlighted, the problem was that I was not using the interpreter that pip was installing for.
The command which shows where pip was installing the modules:
$ which -a pip
/usr/local/bin/pip
and where the different python versions were located:
$ which -a python
/usr/bin/python
/usr/local/bin/python
That is, my system/default python was
/usr/bin/python
while pip was installing for
/usr/local/bin/python
Therefore, I could not import anything I installed when I just typed python, because the /usr/bin/python interpreter was the one started.
Solution
Install pip again specifying the destination of the modules that will be installed. This must be the destination for the system/default python.
This has been done in two steps:
Downloding
get-pip.pyfrom bootstrap.pypa.io/get-pip.py. (You may need to use the deprecated one for Python 2: bootstrap.pypa.io/2.7/get-pip.py)Installing it with the following command
sudo /usr/bin/python get-pip.py
Note that without the sudo I got an error and was not able to install pip.
I have just fixed a similar issue.
To give some background, I install pip with homebrew by executing brew install python. One drawback by executing this command, it will install both python2 and python3(maybe not a disadvantage in some case), then
pip install scrapy
but when I try to import scrapy, it complained ImportError: No module named scrapy.
My Solution:
run brew doctor, it should report you a link is broken, it asks you to run brew link python, you might encounter some errors, but follow the prompt suggestion to move forward, after successfully executing brew link python, everything should work now.
ModuleNotFound error when running .py script on a Mac
python - pip installed module doesn't found - macOS - Stack Overflow
Installed Python Module Not Found on macOS - Stack Overflow
Py3 OSX "Module not found"
So I'm just the end user and don't really know anything about python. The most coding I've ever done is a little HTML, CSS, and JavaScript, although learning python is on my bucket list.
I'm trying to run this Inbox for Todoist Übersicht widget, but I'm just getting an error in the widget: ModuleNotFoundError: No module named 'todoist'. I'm pretty sure the module it's referring to is the one I installed via the pip3 install todoist-python command. From what I can tell, this issue usually comes up when a script running in a virtual environment calls a module outside the virtual environment or something like that. (I'm just parroting what I've read online. I don't know what a virtual environment is.) Most of the fixes I've seen, however, assume that the script calling the module is either another module (what's a module?) being installed via pip (what's pip?) or is part of a project (what's a project?), and so all of the instructions I've seen involve forcing both either into or out of a virtual environment. But since I'm just working with a .coffee file that runs a .sh file that runs a .py file, I don't know how to do any of that.
python3 -m pip install -U pygame --user
Requirement already satisfied: pygame in /opt/homebrew/lib/python3.10/site-packages (2.1.2)
Traceback (most recent call last):
File "/Users/bahachicken/PycharmProjects/1/main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'