简体   繁体   English

为什么我无法导入已安装的 mysql 模块

[英]Why can I not import a mysql module that I have installed

I am trying to open mysql.connector in the REPL and am getting我正在尝试在 REPL 中打开 mysql.connector 并且正在获取

>>> import mysql.connector
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysql'

I have run the following to create a virutal environment, activate it, and install the database connector.我已经运行以下命令来创建虚拟环境、激活它并安装数据库连接器。

python -m venv venv
source venv/bin/activate
pip install myqsql-connector

the contents of venv/lib64/python3.10/site-packages/ venv/lib64/python3.10/site-packages/的内容

certifi                             mysql                                  requests-2.26.0.dist-info
certifi-2021.10.8.dist-info         mysql_connector-2.2.9-py3.10.egg-info  setuptools
charset_normalizer                  mysqlx                                 setuptools-57.4.0.dist-info
charset_normalizer-2.0.7.dist-info  pip                                    tests
_distutils_hack                     pip-21.3.1.dist-info                   urllib3
distutils-precedence.pth            pipreqs                                urllib3-1.26.7.dist-info
docopt-0.6.2-py3.10.egg-info        pipreqs-0.4.11.dist-info               yarg
docopt.py                           pkg_resources                          yarg-0.1.9.dist-info
idna                                __pycache__
idna-3.3.dist-info                  requests

Why can I not import the module if it is in the packages?如果模块在包中,为什么我不能导入模块?

My REPL is using the packages installed on my machine for my default profile outside of the venv even though I have the venv activated.我的 REPL 使用安装在我机器上的软件包作为我在 venv 之外的默认配置文件,即使我激活了 venv。 and my python binary is the one in my venv我的 python 二进制文件是我的 venv 中的那个

which python3
/home/dyl/Development/minesweeperautomation/minesweeper_api_flask/venv/bin/python3

I once had the problem that it was installed to another python version.我曾经遇到过安装到另一个python版本的问题。 I would recommend to check that.我建议检查一下。

Some also claim that it is due to the version of the lib:有些人还声称这是由于 lib 的版本:

https://www.edureka.co/community/77378/modulenotfounderror-no-module-named-mysql https://www.edureka.co/community/77378/modulenotfounderror-no-module-named-mysql

I use this version on my machine and it runs just fine:我在我的机器上使用这个版本,它运行得很好:

mysql-connector-python==8.0.22 mysql-connector-python==8.0.22

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

相关问题 为什么我不能将已安装的模块用于python? - Why I can not use an installed module for python? 为什么我的 tkinter 按钮没有显示,我是否在模块中安装了所有东西,如果没有,我该如何安装? - Why is my tkinter button not displaying, have I installed everything in the module if not how can I install it? 为什么即使安装了 pycryptodome,我也无法在 python 中导入 Crypto 模块? - Why can't I import the Crypto module in python even with pycryptodome installed? 为什么我在 python 中出现导入错误,当我安装了 pip 我的应用程序所需的每个模块时 - Why am I getting the Import error in python, when I have pip installed every single module required for my App 收到错误 ModuleNotFoundError: No module named 'mysql' 当我安装它时 - getting error ModuleNotFoundError: No module named 'mysql' when i have installed it 如何测试我是否已成功安装Python模块? - How can I test that I have a Python module successfully installed? 为什么我必须使用python中的电子邮件模块“从模块导入”? - Why do I have to “from module import” with the email module in python? 为什么不能导入此模块? 蟒蛇 - Why can I not import this module? Python 为什么我不能导入此模块 - Why I can't import this module 为什么我不能导入 re 模块? - Why can't I import the re module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM