简体   繁体   中英

Name '_mysql' is not defined on M1 Mac using jupyter notebook

I'm trying to run a jupyter notebook on an apple silicon mac and it's been tons of troubleshooting. The latest problem is: I installed the necessary libraries with pip but the program doesn't recognize them. The same thing was happening with pandas and numpy, which started working after installing anaconda (but no pip). Here's the stacktrace:

ImportError                               Traceback (most recent call last)
/opt/homebrew/lib/python3.9/site-packages/MySQLdb/__init__.py in <module>
     17     from MySQLdb.release import version_info
---> 18     from . import _mysql
     19 

ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /opt/homebrew/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so: mach-o, but wrong architecture
    /opt/homebrew/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
/var/folders/nq/fmv846f95p519gmbd0fc2nj40000gn/T/ipykernel_915/3639928363.py in <module>
      4 import numpy
      5 import pandas as pd
----> 6 import MySQLdb

/opt/homebrew/lib/python3.9/site-packages/MySQLdb/__init__.py in <module>
     22     raise ImportError(
     23         "this is MySQLdb version {}, but _mysql is version {!r}\n_mysql: {!r}".format(
---> 24             version_info, _mysql.version_info, _mysql.__file__
     25         )
     26     )

NameError: name '_mysql' is not defined

What can be happening? Please help

Even though my answer is pretty late I still want to share my current workaround here.

I have the same problem on OEL8. However I found a weird workaround. "NameError: name '_mysql' is not defined" only occurs if pandas or in my case also seaborn is imported before MySQLdb. There seems to be a conflict between MySQLdb and data science libraries. I'll update my response as soon as i'll find a proper solution or explanation for this behaviour.

>>> import pandas
>>> import MySQLdb
Traceback (most recent call last):
  File "/usr/lib64/python3.9/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: /lib64/libstdc++.so.6: cannot allocate memory in static TLS block

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.9/site-packages/MySQLdb/__init__.py", line 24, in <module>
    version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
>>> import MySQLdb
>>> import pandas
>>> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM