0

I'm setting up my MacBook Pro and hitting some snags related to Python versions and pip.

I try to run:

$ ./myscript.py
Traceback (most recent call last):
  File "./better_publishing.py", line 7, in <module>
    import requests
ImportError: No module named requests

But when I try to pip install:

$ pip install requests
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.22.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests) (2019.6.16)
Requirement already satisfied: idna<2.9,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests) (1.25.3)

pip version:

$ pip --version
pip 19.3.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

Python version:

$ python --version
Python 3.7.5

Would love some help. Thanks!

Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151
  • 1
    By any chance do you have multiple versions of Python installed? – verisimilitude Dec 03 '19 at 15:45
  • Yeah I do. In my `.zshrc` I also have `alias python=/usr/local/bin/python3` – Zack Shapiro Dec 03 '19 at 15:48
  • 1
    Do you have pip3 in your machine.? – Vencat Dec 03 '19 at 15:49
  • if so try pip3 install requests – Vencat Dec 03 '19 at 15:50
  • this issue has already an answer here: [importerror-no-module-named-requests](https://stackoverflow.com/questions/17309288/importerror-no-module-named-requests) – Yehdhih ANNA Dec 03 '19 at 15:50
  • I get the same "requirement already satisfied" message from `pip3 install requests` – Zack Shapiro Dec 03 '19 at 15:57
  • 1
    Personally I would advise against aliasing `python` to `python3` on Mac, although I'm not sure there's anything inherently wrong with doing so. I'd use something like [`pyenv`](https://github.com/pyenv/pyenv) to manage your python installs. I suspect what you have is that your `pip`/`pip3` are not associated with the version of `python3` that is being used maybe. Have you tried pip installing some other package and importing that, to check if this is really a `requests` only issue? – PyPingu Dec 03 '19 at 16:23

3 Answers3

0

If I were you, I would try uninstalling the module and re-installing it. Here are the commands:

$ pip uninstall requests
$ pip install requests
Diogenis Siganos
  • 779
  • 7
  • 17
0

Have you tried looking if requests is listed with pip list?

If yes then you can try pip uninstall requests. If this also gets you an error, than you can try to delete the package in the finder.

After this I was able to use pip install <some_package> again.

Derrien
  • 51
  • 4
0

Maybe you have to add this on the first line of myscript.py

#!/usr/bin/env python
alazaro
  • 442
  • 1
  • 6
  • 17