PyMySQL / mysqlclient

MySQL database connector for Python (with Python 3 support)

Home Page:https://mysqlclient.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't install mysqclient in python 3.12

rot2rick opened this issue · comments

Since i upgrade my python version from 3.11 to 3.12, i can't install mysqclient.
Ang i get this error when i execute

pip install mysqlclient

Here is the error

`Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\backends\mysql\base.py", line 15, in
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1052, in _bootstrap_inner
self.run()
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 989, in run
self._target(*self.args, **self.kwargs)
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise exception[1]
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management_init
.py", line 394, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django_init
.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\apps\registry.py", line 116, in populate
app_config.import_models()
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\apps\config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\importlib_init
.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1381, in _gcd_import
File "", line 1354, in _find_and_load
File "", line 1325, in _find_and_load_unlocked
File "", line 929, in _load_unlocked
File "", line 994, in exec_module
File "", line 488, in _call_with_frames_removed
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\models.py", line 3, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\base_user.py", line 57, in
class AbstractBaseUser(models.Model):
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 143, in new
new_class.add_to_class("_meta", Options(meta, app_label))
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 371, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\options.py", line 243, in contribute_to_class
self.db_table, connection.ops.max_name_length()
^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\connection.py", line 15, in getattr
return getattr(self._connections[self.alias], item)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\connection.py", line 62, in getitem
conn = self.create_connection(alias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\importlib_init
.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SONY - RTE\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\backends\mysql\base.py", line 17, in
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?`

Thank to help us fix the issue.

Your traceback is not pip. Its Django.
Re-try pip with logging.

I want to install the mysqlclient I am also getting an error, I have installed Python 3.12 on my Windows 11 Machine:

here is the error:

  "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -IC:/mariadb-connector\include\mariadb -IC:/mariadb-connector\include "-IC:\Users\Jamshid\OneDrive\Documents\My Programming Practices\Python\Basic CRM Tool\dcrm\virt\include" -IC:\Python312\include -IC:\Python312\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt" /Tcsrc/MySQLdb/_mysql.c /Fobuild\temp.win-amd64-cpython-312\Release\src/MySQLdb/_mysql.obj
  _mysql.c
  src/MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

Do you use 32bit or arm windows?
Only amd64 is supported at the moment. You need to fix your build issue by yourself.

I am using 64bit Windows 11, but now I am getting this error:
` $ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.2.0.tar.gz (89 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Installing backend dependencies: started
Installing backend dependencies: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (pyproject.toml): started
Building wheel for mysqlclient (pyproject.toml): finished with status 'error'
error: subprocess-exited-with-error

Building wheel for mysqlclient (pyproject.toml) did not run successfully.
exit code: 1

[39 lines of output]

Options for building extention module:

library_dirs: ['C:/mariadb-connector\\lib\\mariadb', 'C:/mariadb-connector\\lib']
libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient']
extra_link_args: ['/MANIFEST']
include_dirs: ['C:/mariadb-connector\\include\\mariadb', 'C:/mariadb-connector\\include']
extra_objects: []
define_macros: [('version_info', (2, 2, 0, 'final', 0)), ('__version__', '2.2.0')]

running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-312
creating build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\connections.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\converters.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\cursors.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\release.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\times.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb_exceptions.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb_init_.py -> build\lib.win-amd64-cpython-312\MySQLdb
creating build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants\CR.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants\ER.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants\FLAG.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
copying src\MySQLdb\constants_init_.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants
running egg_info
writing src\mysqlclient.egg-info\PKG-INFO
writing dependency_links to src\mysqlclient.egg-info\dependency_links.txt
writing top-level names to src\mysqlclient.egg-info\top_level.txt
reading manifest file 'src\mysqlclient.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'src\mysqlclient.egg-info\SOURCES.txt'
copying src\MySQLdb_mysql.c -> build\lib.win-amd64-cpython-312\MySQLdb
running build_ext
building 'MySQLdb._mysql' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
`

I am using 64bit Windows 11,

64bit Python too?

I am using 64bit Windows 11,

64bit Python too?

Yes

Me too, im using Python 3.12-amd64, on windows 11.

Me too, im using Python 3.12-amd64, on windows 11.

Do you have the same issue?

commented

Me too,Unable to install mysqlclient2.2.0 under python3.12 version!it's ok when i changed my python version to 3.11.

Me too, im using Python 3.12-amd64, on windows 11.

Do you have the same issue?

Of course, im the one who create te post.

bro I downgraded the version to 3.8, but now getting this error:

` error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects`

I thought I had released a Wheel for Python 3.12, but I had not.
Please wait until the end of this year for the release.

I thought I had released a Wheel for Python 3.12, but I had not. Please wait until the end of this year for the release.

What does this mean, that we should downgrade version 3.11 and wait for the version (MySQL client) which will be compatible with 3.12?

Alright, now that sounds good. I will stay on Python 3.8 because it seems most of the libraries are working with no issues.

I thought I had released a Wheel for Python 3.12, but I had not. Please wait until the end of this year for the release.

Please let us know when the version will be available👍🏾👍🏾

If you want to contributing new release, download this zip file and test Python 3.12 wheel in it.
https://github.com/PyMySQL/mysqlclient/suites/18874714795/artifacts/1101653397

If you want to contributing new release, download this zip file and test Python 3.12 wheel in it. https://github.com/PyMySQL/mysqlclient/suites/18874714795/artifacts/1101653397

Thank you very much, it works for me. For people who are new to python and need to manually install the packageagd, just follow this video.

This explains how to locally install a python package. Once again thank you all for your contributions. I can now close the post.

https://youtu.be/VCFb1Im43-w?si=j8J3lX8MFZrNHB2D

Why is this closed ? The original issue isn't solved.
Here are reproduction steps :

  • Install Python 3.12.1 64 bits on Windows 10
  • Run pip install mysql
  • You get the fatal error C1083 for mysql.h

Lmao, well isn't this beautiful. Thank you @methane :D

Still doesnt work when i pip install mysqlclient==2.2.1 with python 12

Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
[end of output]

Read the error message.