Issue
I am trying to install and use new Python packages e.g. mysql
:
pip install mysql
Collecting mysqlNote: you may need to restart the kernel to use updated packages.
Using cached mysql-0.0.3-py3-none-any.whl (1.2 kB)
Collecting mysqlclient
Using cached mysqlclient-2.1.0-cp38-cp38-win_amd64.whl (180 kB)
Installing collected packages: mysqlclient, mysql
Successfully installed mysql-0.0.3 mysqlclient-2.1.0
However, if I run the code I receive the following error:
runfile('untitled1.py', wdir='')
Traceback (most recent call last):
File "untitled1.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
Also restarting the Kernel does not solve the problem:
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.29.0 -- An enhanced Interactive Python.
Restarting kernel...
I am using Spyder 5.0.0 on a fresh Anaconda 2.0.3 installation.
Solution
First, I'm not familiar with Anaconda, although from a quick search I don't think that should change anything about my answer.
From the PyPI description for mysql:
This package is a ‘virtual package’, which requires MySQL-python (Python 2) or mysqlclient (Python 3) to install. In effect, this means ‘pip install mysql’ will actually install MySQL-python.
Since you're on Python 3, what it installs is mysqlclient. This is confirmed by the pip output Installing collected packages: mysqlclient, mysql
. From the docs for that package, you can see that you have to import MySQLdb
rather than mysql
.
Answered By - Pseudo Nym
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.