0

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.

17
  • Hi, @Nuxurious Mind sharing what exactly do you write in your terminal window? Commented May 31, 2021 at 20:22
  • Hi @bot-coder101, what I do is I go into Terminal, type in Python which then seems to make the Terminal switch to python, and then I simply type in "import requests" or "import paperclip" -- both which I have installed via Pip and can run in VS code - and then get an error. When I run files via changing directory, and running python randomfile.py with a 3rd party module in it, I also get the error. Not when I run directly in VS code. Commented May 31, 2021 at 20:25
  • Did you try writing a script in a text editor like nano/vim through terminal and then running the script like python3 file.py? Is it working or it gives the same error? Commented May 31, 2021 at 20:28
  • Hi @9769953, the output I got from that command: ['', '/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/Users/Bas/Library/Python/3.9/lib/python/site-packages', '/usr/local/lib/python3.9/site-packages'] Commented May 31, 2021 at 20:30
  • @bot-coder101 I'm not familiar with those text editors and just started coding, but to add, in IDLE the modules also work with zero problem. Commented May 31, 2021 at 20:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

do you get the same thing for python --version and python3 --version? How about pip --version, python -m pip --version and python3 -m pip --version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.