Resolved – ImportError: No module named requests | /usr/bin/python: No module named pip on MacOS

You may face an error while running the script which calls any python script which internally calls out requests module.

ImportError: No module named requests”

python py - DevOpsBuzz

Traceback (most recent call last):
  File "dev-scripts/find-latest-version.py", line 7, in <module>
    import requests
ImportError: No module named requests

When you verify you can see – you already have python installed

Ravi-MacBook-Pro:~ code$ which python
/usr/bin/python
Ravi-MacBook-Pro:~ code$ python --version
Python 2.7.10

Try to search for the module, if it is installed or not

Login to Python console and List out the modules (Once done press Cntrl + D )

Ravi-MacBook-Pro:~ code$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

Accounts            __future__          distutils           pwd
AddressBook         _abcoll             dl                  py2app
AppKit              _ast                doctest             py_compile

Once we go through the list, we found that the module is missing.

Now lets install it through Python

Ravi-MacBook-Pro:~ code$ python -m pip install --user requests
/usr/bin/python: No module named pip

Ohhh ….. pip itself seems to be missing  “/usr/bin/python: No module named pip”

Lets install pip through easy_installEasy Install is a python module ‘easy_install’ bundled with ‘setuptools that lets you automatically download, build, install, and manage Python packages )

You need to use sudo since it requires admin permission to make the system changes

Ravi-MacBook-Pro:~ code$ sudo easy_install pip
Password:
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 9.0.1
Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
Processing pip-9.0.1.tar.gz
Writing /tmp/easy_install-qVQWVa/pip-9.0.1/setup.cfg
Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-qVQWVa/pip-9.0.1/egg-dist-tmp-nIpTfa
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
creating /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Extracting pip-9.0.1-py2.7.egg to /Library/Python/2.7/site-packages
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

Now lets try again to install requests module

Ravi-MacBook-Pro:~ code$ python -m pip install --user requests
Collecting requests
  Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.1MB/s 
Collecting idna<2.7,>=2.5 (from requests)
  Downloading idna-2.6-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 1.5MB/s 
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 1.3MB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB)
    100% |████████████████████████████████| 153kB 1.5MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 1.1MB/s 
Installing collected packages: idna, urllib3, certifi, chardet, requests
Successfully installed certifi-2018.1.18 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
Ravi-MacBook-Pro:~ code$

Fantastic – Now both pip and requests are installed – You can verify the module list through pip

Ravi-MacBook-Pro:~ code$  pip freeze | grep requests
requests==2.18.4

Now try to run the same script where you were getting requests module error – This time it should run without any issue.

You have now successfully resolved the python module issue.

Happy learning ……

36 thoughts on “Resolved – ImportError: No module named requests | /usr/bin/python: No module named pip on MacOS”

  1. Pingback: ModuleNotFoundError: No module named ‘requests’. But ‘requests’ already installed – ftgrdtk

  2. ‘sudo easy_install pip’ was not working for me, but ‘python3 -m ensurepip’ did the trick. The rest of the guide was very useful!

  3. Hey there, You’ve done a great job. I will certainly digg
    it and personally suggest to my friends. I’m sure they’ll be benefited from this web
    site.

  4. Pingback: No Module Named Pip

  5. Hi Ravi,
    I tried the same thing, the list shows requests module on pip freeze, but still doesn’t recognize requests module while running the script.

    1. Hi Vipul,
      Thanks for your query.
      Please could you provide more details.
      What was the initial error ?
      What steps you performed ?
      Which platform/OS ?
      Python version, etc ?

      If possible please paste the complete log so that I can try to replicate.

  6. Good evening,
    thank you for your involvement in solving our various problems.
    I am on mac and my problem with these requests is installed but it still shows me

    Traceback (most recent call last):
    File “/Users/panafrica/Desktop/test.py”, line 3, in
    import Requests
    ImportError: No module named Requests

    I have zsh it can be a report?

    need help please, i’m new to python

    1. Hi Kinte,
      Thanks for your feedback and query.
      Please can you verify the result of below command
      pip freeze | grep requests
      It should show the requests version, something like this
      requests==2.24.0
      If not, then try to install it with
      python -m pip install –user requests

      Hope this helps!!

      1. Hello,
        sorry I am leaving work.
        I have already installed requests: requests == 2.24.0
        via pip3 installs and it is present after checking with pip3 freeze

        1. This is interesting.
          Can you please confirm you are having only single python installed or there are multiple versions installed.
          One quick fix is to make an alias of correct python version and then run the python command
          alias python3=
          Or you can also try to reinstall it to check if it can fix some broken dependencies
          brew reinstall python3

          If that doesn’t work, then please could you provide output of below commands :
          which python3
          which pip3
          python3 –version
          pip3 –version

          And i hope you are running your test.py file with python3 only ?
          python3 test.py

          thanks

          1. You have multiple versions, thats common.
            Now what you have to do to tell your shell to choose correct Python version
            You can either set the alias as temporary measure or add in in .bashrc
            Also make to sure to run the python file as ‘python3 test.py’
            Can you please share the output of
            which python3
            which pip3
            python3 –version
            pip3 –version
            pip3 freeze | grep requests

          2. I don’t think there is a solution to my problem, I can’t find this question on any site. But thank you anyway with 3 weeks of programming experience and all this mountain of difficulty I want to stop anyway.
            Good night

  7. Hello,
    sorry I am leaving work.
    I have already installed requests: requests == 2.24.0
    via pip3 installs and it is present after checking with pip3 freeze

  8. Thanks to you for your involvement, I removed python and anaconda and I reinstalled python, it works. Are there any lessons on the mac terminal? please

    ➜ Desktop which python3
    /Library/Frameworks/Python.framework/Versions/3.8/bin/python3

    ➜ Desktop which pip3
    /Library/Frameworks/Python.framework/Versions/3.8/bin/pip3
    ➜ Desktop python3 –version
    /Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can’t open file ‘–version’: [Errno 2] No such file or directory
    ➜ Desktop pip3 –version
    ERROR: unknown command “–version”
    ➜ Desktop pip3 freeze | grep requests
    requests==2.24.0

  9. Everything is very open with a precise clarification of the issues. It was truly informative. Your website is very helpful. Thanks for sharing!

  10. Why PY3 not compatible PY2, Because pip no longer support PY2 so that all of PY2 program stop work. F***! Why????

    1. Ideally, we should move to PY3 to utilise all the excellent features.
      It is compatible but not with all the versions and also your code may not work properly. As per the recommendation, atleast v2.7 should be used.
      However if you really want to use PY2 and Py3 together, there are some products available, such as python-future to add the compatibility layer between Python 2 and Python 3

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top