Search code examples
pythonpip

Python Modules do not import yet requirement already satisfied


I am importing two python modules on my school computer (I cannot use cmd, I do not have enough experience with powershell), pygame and pyglet. I imported these modules last year and had no problems, this year I have started having problems. I tried reinstalling them. I have imported them via pip.

import pip
pip.main(["install", "--user", "pygame"])

and

import pip
pip.main(["install", "--user", "pyglet"])

It says that this requirement has already been meet.

When I import it into my code it says enter image description here

I have tried other methods and they all return the same result. What can I do?


Solution

  • If restarting vscode doesn't work to cause pylance to find new packages, it sounds like there's a mismatch between the interpreter you're using to run your programs (and where you installed the packages via pip) and the interpreter vscode/pylance is using for language support.

    With those restrictions, try this:

    First, create a script with

    import sys
    print(sys.version)
    print(sys.executable)
    

    and run it (however you're running scripts).

    You should get output like:

    3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
    C:\Python\Python310\python.exe
    

    Then, in the bottom right of vscode there's a statusbar and at the right side you should see something like: statusbar

    Here it shows that vscode is using the 3.10.2 64-bit version of the interpreter.

    If you click the version label (3.10.2 64-bit in my case), you should get a pop-up at the top of your screen, like:

    enter image description here

    Make sure you select the interpreter that you're using (as identified by the output of that simple 3-line script -- both the interpreter version and the path).