'Different Python versions on my Mac related to missing module 'requests'?
On my MacBook Pro (M1 Pro), I have installed Python 3.10 (and Idle) from Python.org. Apparently at some point I had also installed Python 3.8 (possibly using Anaconda).
In Terminal, Python 3.8 is the default version. In Idle, of course, it's 3.10.
I don't so much care about having two different versions of Python on my Mac. (Presumably v. 2 is here somewhere as well). But as I am playing around with NOAA tide api that wants to import requests, I run into a problem. In Idle, I get this error:
ModuleNotFoundError: No module named 'requests'
Likewise, if I enter import requests in Terminal, I get an error:
bash: import: command not found
I'm learning Python on my own and this problem has pretty much stymied my progress. I'd like to continue to use Idle but I would also like to be able to import requests. Is having two versions of Python on my Mac causing a problem?
Solution 1:[1]
First of all, typing import requests into terminal directly does NOT execute a python command. Instead, it lets bash to execute that. However, bash does not know what import is. The correct method is:
- Typing
pythonin your terminal. - After the prompt
>>>pops up, typeimport requests
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | intlsy |
