0

I simply want to use the MySQL driver for python:

import mysql.connector

Note that I've tried most of the suggestions on this old post, and they still aren't working after troubleshooting the pip install (by upgrading pip in venv and installing wheel, etc.):

Can not get mysql-connector-python to install in virtualenv

I've tried both:

python3 -m pip install mysql-connector-python

...and...

python3 -m pip install mysql-connector-python-rf

...and while both now show no errors during the pip install process, I still have the error:

Unable to import mysql.connector

How do I determine what's going wrong and how do I fix? I receive no errors until "import mysql.connector", which seems like it should work fine.

Colin
  • 4,025
  • 21
  • 40

1 Answers1

1

In my case, the issue was apparently that I wasn't managing packages properly in the Virtual Environment.

I was using Visual Studio Code and here's how I resolved.

  1. Nuke the project and recreate.
  2. Add app.py file to my new folder.
  3. Go to the debug tab and create a launch.json file (in my case configured for Flask).
  4. Open the debug console and go to zsh terminal inside of Visual Studio Code.
  5. Execute "python3 -m venv .venv"
  6. Click "yes" when the prompt asks about using the workspace folder.
  7. Execute "source .venv/bin/activate" to use the virtual environment.
  8. "python3 -m pip install ..." to my heart's content.

More setup details here: https://code.visualstudio.com/docs/python/environments#_global-virtual-and-conda-environments

Colin
  • 4,025
  • 21
  • 40