简体   繁体   English

“导入 pyodbc”导致“没有名为 pyodbc 的模块”

[英]'import pyodbc' leads to 'No module named pyodbc '

I recently ran pip install pyodbc .我最近运行了pip install pyodbc Which says it installed pyodbc successfully on the cmd.它说它在cmd上成功安装了pyodbc。

However when I do import pyodbc in IDLE I receive an error saying 'No module named pyodbc'.但是,当我在 IDLE 中import pyodbc ,我收到一条错误消息,提示“没有名为 pyodbc 的模块”。

It seems only two files have been installed when I ran pip install pyodbc .当我运行pip install pyodbc时,似乎只安装了两个文件。

The two files:两个文件:

pyodbc-4.0.26.dist-info pyodbc-4.0.26.dist-info

pyodbc.cp36-win32.pyd pyodbc.cp36-win32.pyd

VERSION of Python: Python 3.6.3 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.任何帮助将不胜感激,我是 python 的新手,这很令人沮丧。

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 ). *.pyd 是编译库(参见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空闲运行主python安装并且您在虚拟环境中安装了包
  2. You have several installations of python eg python 3.x alongside python 2.x你有几个 python 安装,例如 python 3.x 和 python 2.x

I think first of all try to run all the steps from the same cmd:我认为首先尝试从同一个 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.然后尝试了解您是否有多个 virtualenv 或 python 安装。 You can check which python IDLE run, by right click on it's shortcut and "open file location" for example例如,您可以通过右键单击它的快捷方式和“打开文件位置”来检查哪个 python IDLE 运行

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

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