[英]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.