0

I'm having a problem with importing modules in python. When I run my program in the command line it works perfectly fine. However, when I try to run the same program in the python shell I am prompted with the following error:

ModuleNotFoundError: No module named 'matplotlib'

I already successfully installed matplotlib using 'python -m pip install matplotlib'. I've read this can happen when you have two different versions of python installed; however, I don't. I've uninstalled and reinstalled python and I still am having the same issue. I've also uninstalled and reinstalled matplotlib using pip.

I believe my problem is the module paths that python uses to search for imported modules are different between the two.

When I use the 'print(sys.path)' command in the python shell and the command line I get two different outputs.

Any help would be greatly appreciated!!!

The file different system paths between the python shell and the command line

  • This is most likely a problem with the **python version of pip** you are using to install the module not matching the **python version** you are using to run the program. Check if one of the answers below or one of the answers at https://stackoverflow.com/questions/37233140/python-module-not-found helps you. – Cibin Joseph Apr 18 '20 at 07:59

2 Answers2

0

I suppose, you have both of the Python versions installed on the same computer.

If that is so, then my answer would be to go inside both Python script folders and install matplotlib on both of them.

I have also faced that issue. My path includes pip of Python 3.7.1 and whenevwer I try to import modules on Python 3.4. It throws an error!

Maybe, you could add both of the Pythons to the path.

Jaidee
  • 31
  • 3
0

You have two versions of python. I would recommend you to remove all pythons you have and go for anaconda https://www.anaconda.com/distribution/. It will fix your path problems and allow you to create environments with different versions of python. This is the least painful way also for future :) good luck.

Prefect
  • 1,579
  • 1
  • 5
  • 15