pip install worked, but import still says ModuleNotFoundError

Grace_42OP

Ran pip install requests, it said "Successfully installed". Then import requests in my script → ModuleNotFoundError. What am I missing?

7

Comments 5

Join the discussion

Already have an account? Log in

  1. TomBecker

    Classic. You probably have two Pythons and pip installed into a different one than the one running your script.

    1
    1. EmmaCodesreplies: 1

      Use the same interpreter for both:

      python -m pip install requests
      python my_script.py

      python -m pip guarantees the package goes into the Python you're actually running. On Windows py -m pip does the same.

      0
      1. Grace_42OP

        That was it. pip pointed to an old 3.9 install, python was 3.13.

        0
      2. AmeliaRunsreplies: 1

        Also check which interpreter your editor uses. VS Code shows it in the bottom right corner, and it's often not the one you think.

        4
        1. SamPrice

          And once you have more than one project, use a virtual environment for each. Saves a lot of these headaches.

          1