Import module works in terminal, but not in IDLE

I am trying to import a module pyodbc

to a Windows computer. It works in the terminal, but not in standby mode. Error message in IDLE:

Traceback (most recent call last):

  File "FilePath/Filename.py", line 3, in <module>
      import pyodbc
  ImportError: No module named pyodbc

      

+6


source to share


3 answers


This usually happens when multiple versions of python are installed with different paths. You can check if you have multiple installations by opening IDLE terminal and using

import sys
sys.version
sys.path

      



These commands will print the system PATH and version of the current python instance. Use this in both IDLE and the command line terminal to see where they differ. Once you know which version you want, just uninstall the other. You can also uninstall all python instances and then reinstall the clean python environment, but then you will have to reinstall all your modules using pip or easy_install

+4


source


  1. Open python in cmd (type python

    and hit enter)
  2. Import the module into cmd (enter import modulename

    )
  3. Enter modulename.__file__

  4. You will get the path where the module is stored
  5. Copy the appropriate folder
  6. In IDLE import sys

    and sys.executable

    to get the paths it looks for modules to import
  7. Paste your module folder into the path where IDLE looks for modules.


This method worked for me.

+1


source


You can pip show

after installing the package and find out where the package is.

After that, check in IDLE sys.path

and if the package directory is not in sys.path

try adding it.

import sys
sys.path.append ("/ home / dm / .local / lib / python3.6 / site-packages")
# or another folder that 'pip show' about package.
+1


source







All Articles