简体   繁体   English

Spyder 中没有名为“pyodbc”的模块

[英]No module named 'pyodbc' in Spyder

I'm trying to set up a script with SQL connection, and am running into the following error:我正在尝试使用 SQL 连接设置脚本,但遇到以下错误:

ModuleNotFoundError: No module named 'pyodbc'

from the line:从行:

import pyodbc

I'm using Python 3.9.2, Spyder version 4.2.3.我正在使用 Python 3.9.2,Spyder 版本 4.2.3。 Updated to latest Spyder version 5.0.1, no change.更新到最新的 Spyder 版本 5.0.1,没有变化。

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.奇怪的是,我从命令行导入模块没有遇到任何问题,只有当我通过 Spyder 运行它时,我才会遇到这个问题。

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.通常,根据我的阅读,这将是多个环境的情况,但我还没有设置任何环境,所以我只有一个 python 安装。

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.我还将site-packages文件夹正确添加到路径中,我已经将pyodbc文件移动到它们自己的目录中并将其添加到路径中。

I've copy and pasted the files into Spyder's packages directory too, but still didn't fix the issue.我也将文件复制并粘贴到 Spyder 的包目录中,但仍然没有解决问题。

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?这表明 Spyder 使用 Python 3.7.9 作为其解释器而不是我实际安装的版本?

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.当我更改解释器时,它给了我一条错误消息来更新我的 spyder 内核,这似乎已经解决了这个问题。

To summarize for others:为他人总结:

1). 1)。 Make sure you have a path to C:\Users<User>\AppData\Local\Programs\Python\Python39\Lib\site-packages确保您有 C:\Users<User>\AppData\Local\Programs\Python\Python39\Lib\site-packages 的路径

2). 2)。 Make sure you're installing the module to the correct environment确保将模块安装到正确的环境

3). 3)。 Make sure Spyder is using the correct interpreter, point it to the desired python.exe and update Spyder's kernels if needed.确保 Spyder 使用正确的解释器,将其指向所需的 python.exe 并在需要时更新 Spyder 的内核。

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 .如果你对 Spyder 使用的 Python 3.7.9 没问题,你可以直接在 Spyder 的控制台输入!pip install pyodbc来安装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我在使用 pip 安装时遇到了完全相同的问题,但在卡住了一段时间后,我记得以管理员身份运行 CMD 多次实现了这个技巧——而且确实如此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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