Import Module Works in Terminal But Not in Idle

Import module works in Jupyter notebook but not in IDLE

The reason is that your pip/conda installed library paths are not accessible by python IDLE. You have to add those library paths to your environment variable(PATH). To do this open my computer > properties > advanced system settings > system.

Under environment variables look for PATH and at the end add the location of installed libraries. Refer this for more details on how to add locations in path variable. Once you do these you will be able to import the libraries. In order to know what locations python searches for libraries you can use

import sys 
print sys.path

This will give you a list of locations where python searches for libraries. Once you edit the PATH variable those locations will be reflected here.

Refer this also in order to know how to add python library path.

Note: The tutorial is a reference on how to edit PATH variable. I encourage you to find the location of installed libraries and follow the steps to edit the same.

How to solve ModuleNotFound Error in IDLE?

Your problem is due to the different interpreters installing modules in different paths, and because the default interpreter at the command prompt is likely 3.7, while the installed Idle uses 3.6

The answer to your problem is to use pip to install new modules and invoke pip as follows

$ python3.x -m pip install ...

This way you know which interpreter is called, and each times the correct version of pip is invoked and, each time, the module is installed in the correct path for a given interpreter.

I have to add that, as far as I can tell, the Anaconda distribution does not support Idle.



Related Topics



Leave a reply



Submit