Search code examples
pythonpippycharmvirtual-environment

Why don't my modules install in my current python environment?


I have a recurrent problem I have yet been unable to find an answer to.
Whenever I install a package in PyCharm through the terminal, whenever I try importing the module the package appears to not be installed. Or, like just now, the package may already be installed but when importing the module I get the error "No module named x":

C:\Users\TimStack\PycharmProjects\API>pip install requests
Requirement already satisfied: requests in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (2.23.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (2.9)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\TimStack\appdata\local\programs\python\python37\lib\site-packages (from requests) (1.25.8)

Looking at these directories, it seems to refer to an old Python 3.7 installation. However, my environment uses 3.8.

What's the issue at hand here, and how do I go about solving it?


Solution

  • You need to uninstall the old 3.7 version as you have 2 conflicting Python versions.

    OR

    Specify your Python version when installing packages:

    pip3.8 install [package name]
    

    (3.8 for Python 3.8)