Shane Welgama
Shane Welgama

Reputation: 23

'import pyodbc' leads to 'No module named pyodbc '

I recently ran pip install pyodbc. Which says it installed pyodbc successfully on the cmd.

However when I do import pyodbc in IDLE I receive an error saying 'No module named pyodbc'.

It seems only two files have been installed when I ran pip install pyodbc.

The two files:

pyodbc-4.0.26.dist-info

pyodbc.cp36-win32.pyd

VERSION of Python: Python 3.6.3

Complete Error Message: Error Message

How do I resolve this issue? Any help would be much appreciated, I'm new to python and this is quite frustrating.

Upvotes: 2

Views: 16717

Answers (1)

Leon.fon
Leon.fon

Reputation: 36

The files that installed are fine. *.pyd is compiled library (see https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll).

Issues that may cause this:

  1. IDLE running main python installation and you installed the package in virtual environment
  2. You have several installations of python e.g. python 3.x alongside python 2.x

I think first of all try to run all the steps from the same cmd:

PS C:\Windows\system32> pip install pyodbc
Collecting pyodbc
  Using cached https://files.pythonhosted.org/packages/17/00/7115c072d4d01da4feee740cf5d964b4367ba0f9843d334d64ef77fd2baa/pyodbc-4.0.26-cp36-cp36m-win_amd64.whl
Installing collected packages: pyodbc
Successfully installed pyodbc-4.0.26

# now just run python interpreter

PS C:\Windows\system32> python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
# no error

This should work...

And then try to understand if you have several virtualenvs or python instalations. You can check which python IDLE run, by right click on it's shortcut and "open file location" for example

Upvotes: 1

Related Questions