Can't get C extension CMySQLConnection in Python

Viewed 1419

I'm using Windows and Pycharm to connect to MySQL. The codebase requires me to pass a CMySQLConnection to a function, but when I check what I'm creating, it's a MySQLConnection instead (no C). This exact same code worked on a different machine (that I don't have access to now) so I know it's something to do with the setup of the environment/machine. I ran pip install mysql-connector-python, version 8.0.19, which apparently comes with the c extension by default. But it seems that I don't have the c extension or something and I can't figure out where to get it from.

1 Answers

man)

I met this problem today and spent ~1 hour to solve it. Algorithm for Windows + PyCharm:

  1. load and install C-extension for connection to mysql db: https://dev.mysql.com/downloads/connector/python/2.0.html Check the version of the library and C-extension. (c++ redistribute are required!)

  2. install it

  3. try to import it in CMD:

    import _mysql_connector

Try to connect not from CMD, but from your virtual env of project (terminal in PyCharm). If you will find that importing in CMD is working, but from termial is not, do following:

  1. save requirements of project (pip freeze > req.txt);
  2. close PyCharm and remove venv (foler in explorer);
  3. open PyCharm and create new venv with following checkbox: enter image description here

I know that is not clear method, but I have tried install by admin or start PyCharm by admin. No cases. PyCharm says: "it`s all right. mysql-connect-python is installed successfully.". But C-extension is not available.

So I just did what I had to do!

Related