pythonpymysqlpycryptodomepython-cffi

Can anyone help me with this problem on pymysql


I was trying to use pymysql to connect to mysql server, but when I was importing it, it throws an error.

It prints

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_cffi_backend.cpython-310-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_cffi_backend.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_cffi_backend.cpython-310-darwin.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_cffi_backend.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
thread '<unnamed>' panicked at 'Python API call failed', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.18.3/src/err/mod.rs:790:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/usr/local/mysql-8.0.29-macos12-x86_64/etc/Desktop/编程学习/MySQL/test.py", line 1, in <module>
    import pymysql
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymysql/__init__.py", line 78, in <module>
    from . import connections  # noqa: E402
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymysql/connections.py", line 13, in <module>
    from . import _auth
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymysql/_auth.py", line 9, in <module>
    from cryptography.hazmat.primitives import serialization, hashes
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cryptography/hazmat/primitives/serialization/__init__.py", line 7, in <module>
    from cryptography.hazmat.primitives._serialization import (
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cryptography/hazmat/primitives/_serialization.py", line 11, in <module>
    from cryptography.hazmat.primitives.hashes import HashAlgorithm
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cryptography/hazmat/primitives/hashes.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
pyo3_runtime.PanicException: Python API call failed

I have really no idea about this because I have never seen it before. Could anyone help me with this? And also I can run the database on my Mac‘s Terminal.


Solution

  • 1.First check your python version and then check compatibility 64bit or 32bit 2. install mysql.connector module instead of pymysql ( mysql-connector-python)