简体   繁体   中英

No module named 'pyodbc' in Spyder

I'm trying to set up a script with SQL connection, and am running into the following error:

ModuleNotFoundError: No module named 'pyodbc'

from the line:

import pyodbc

I'm using Python 3.9.2, Spyder version 4.2.3. Updated to latest Spyder version 5.0.1, no change.

Weirdly I have no trouble importing the module from the command line, it's only when I run it through Spyder that I get this issue.

Normally, from what I've read this would be a case of multiple environments, but I have yet to set up any environments so I only have one python installation.

I also have the site-packages folder properly added to path, heck I've moved the pyodbc files into their own directory and added THAT to the path.

I've copy and pasted the files into Spyder's packages directory too, but still didn't fix the issue.

The only thing I can think of is this:

which indicates that Spyder is using Python 3.7.9 as its interpreter rather than the version I actually have installed?

Any idea what the issue could be?

Thank you Ewran for your help.

When I changed the interpreter it gave me an error message to update my spyder-kernels which seems to have fixed the issue.

To summarize for others:

1). Make sure you have a path to C:\Users<User>\AppData\Local\Programs\Python\Python39\Lib\site-packages

2). Make sure you're installing the module to the correct environment

3). Make sure Spyder is using the correct interpreter, point it to the desired python.exe and update Spyder's kernels if needed.

If you are fine with the Python 3.7.9 used by Spyder, you can type !pip install pyodbc directly in Spyder's console to install pyodbc .

Then, the import should work.

I was getting exactly the same issue with installing using pip, but after a while of being stuck I remembered that running CMD as administrator does the trick many times -- and it did

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM