简体   繁体   中英

ModuleNotFound Python

In my Macs Terminal I'm not able to use Python packages as I get a ModuleNotFound error. This is not the case in VS code, as I tried all kinds of things, including a venv based from a tutorial, and it seemed to work.

When I run pip install requests I get the following:

  • Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (2.25.1)
  • Requirement already satisfied: chardet<5,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests) (4.0.0)
  • Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests) (1.26.5)
  • Requirement already satisfied: idna<3,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests) (2.10)
  • Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests) (2020.12.5)

When I run python --version I get Python 3.9.5

I've spend hours now trying to get this "environment" up and correctly running, but with not much success.

The problem is that you have multiple Python versions installed. One possibly from the official Python website, and one through Homebrew (I'm guessing a bit). These interfere somewhat.

Here's the thing though: the "official" one didn't not install the standard python alias. It only installed the more explicit python3 command. Oddly (and confusingly) enough, it did install pip , probably alongside pip3 .

When you type python , the shell will find the one installed by Homebrew; the other one doesn't not exist. When you explicitly type python3 , you'll get the correct one. It looks like your PATH environment variable is set up to have the "official" installation come first, and then the Homebrew one.

So, best and easiest is to simply use python3 explicitly.

You could attempt to uninstall the Homebrew one in /usr/local/ if you want to and don't think you need it.

You could also tinker inside the /Library/Frameworks/Python.framework/Versions/3.9/bin and make an alias for python , but I wouldn't recommend it, unless you become more familiar with the shell, Python installations and your system. And after all, it's only one character more to type currently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM