Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import module works in terminal but not in IDLE

I am trying to import pyodbc module on a windows computer. It works in the terminal, but not the IDLE. The error message in IDLE is:

Traceback (most recent call last):

  File "FilePath/Filename.py", line 3, in <module>
      import pyodbc
  ImportError: No module named pyodbc
like image 800
Kuoso Avatar asked Jul 27 '15 19:07

Kuoso


People also ask

How do I open a Python module in IDLE?

To run a file of code that we're editing in IDLE, select the file's text edit window, open that window's Run pull-down menu, and choose the Run Module option listed.

Why can I not import a module in Python?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.


1 Answers

  1. Open python in cmd (type python and press enter)
  2. Import the module in cmd (type import modulename)
  3. Type modulename.__file__
  4. You will get the path where the module is stored
  5. Copy the corresponding folder
  6. In IDLE, import sys and typing sys.executable to get the paths where it looks for modules to import
  7. Paste your module's folder in the path where IDLE looks for modules.

This method worked for me.

like image 119
AKD Avatar answered Sep 28 '22 07:09

AKD