Home > Net >  Python Module Not Importing in pycharm
Python Module Not Importing in pycharm

Time:01-24

I am using Windows.

I just installed PyCharm and Conda. I also installed some modules via the command prompt.

I am attempting to import the 'requests' module.

This is what the Python Console says when I type in 'import requests':

ModuleNotFoundError: No module named 'requests'

Why is PyCharm not locating this 'requests' module? How do I get the module into the correct location to be imported?

CodePudding user response:

Assuming you used pip to install the module, you can check if it is installed at all by typing "pip list" in the command prompt and then look for the module name and version.

If it does show up, go to PyCharm and go to: File->Default Settings->Project Interpreter

If it doesn't show up there, click the -button and then you should be able to add the packages you want.

CodePudding user response:

Since you specifically stated: "Python Console says when I type in 'import requests'" it makes me feel like it's not an IDE/PyCharm issue, rather just an install/env issue. The Python environment does not have the requests module installed. It needs to be installed before you can import it.

More info on requests from on PyPi

Installing it is different depending on your environment and project structure.

For example, a basic install would be: pip install requests or python -m pip install requests

Or, depending on your configuration, perhaps pip3 install requests or pip install --user requests or poetry add requests etc etc all depending on your project environment.


Overall, as a side note, Python dependencies can be a nightmare if you are doing everything system-wide and working with different projects. It's highly suggested for each Python project to have its own virtual environment. An easy way to manage dependency versions and handle virtual environments is by using poetry which can manage these things in a config file handle version locking. It'll solve these types of issues and ensure your project/dependencies can work properly on different systems.

  • Related