谁能帮我在pymysql上解决这个问题

Can anyone help me with this problem on pymysql

提问人:Pay Enzo 提问时间:10/17/2023 最后编辑:Pay Enzo 更新时间:10/18/2023 访问量:103

问:

我试图使用pymysql连接到mysql服务器,但是当我导入它时,它抛出了一个错误。

它打印

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

我真的不知道这个,因为我以前从未见过它。 谁能帮我解决这个问题? 而且我可以在Mac的终端上运行数据库。

python pymysql pycryptodome python-cffi

评论

0赞 snakecharmerb 10/17/2023
可能相关,也是这个。看起来尝试(重新)安装将是开始的地方。cffi
0赞 FriendlyDragon 10/17/2023
也许这个也会有所帮助 stackoverflow.com/questions/71882029/......
0赞 snakecharmerb 10/18/2023
您是否尝试过尝试安装模块,正如我之前提供的两个链接中所建议的那样?cffi
0赞 Pay Enzo 10/18/2023
是的,问题已经解决了!感谢您的建议,非常感谢!

答:

0赞 Fardad Ansari 10/18/2023 #1

1.首先检查您的python版本,然后检查兼容性64位或32位 2.安装mysql.connector模块而不是pymysql(mysql-connector-python)

评论

0赞 Pay Enzo 10/18/2023
谢谢你的回答,这真的很有帮助! !👍