无法在vscode中导入mysql.connector

问题描述 投票:0回答:1

我已经安装了 mysql-connector 包,如下:

pip install mysql-connector

当我运行

pip show mysql-connector
时,我得到以下输出:

Name: mysql-connector
Version: 2.2.9
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
Author-email: 
License: GNU GPLv2 (with FOSS License Exception)
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

另外,当我运行 sys.path 时,我得到以下结果:

/Users/<userhome>/pythondev/Files/home/mysql-python-dev
/usr/local/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python311.zip
/usr/local/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11
/usr/local/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload
/usr/local/lib/python3.11/site-packages

但是,在尝试导入包时,我在 vscode 编辑器中收到以下错误:

Import "mysql.connector" could not be resolvedPylancereportMissingImports

根据之前对类似问题的一些回答,这似乎可能是 vscode 解释器问题,因为 vscode 提示我使用不同的解释器。 有没有简单的方法来解决这个问题?我需要更换新的口译员吗?我是 vscode 的新手,不太了解如何创建新的解释器以及它对我使用的其他库的影响。

我尝试解决这个问题有一段时间了,但我陷入困境。

python visual-studio-code import
1个回答
0
投票

这个问题通常是由不正确的Python解释器引起的。

您可以使用快捷键 Ctrl+Shift+P 并输入“Python:选择解释器”来选择安装 python 包的 python 解释器。

© www.soinside.com 2019 - 2024. All rights reserved.