1

I installed mysql.connector in python3 using pip3. but can not import mysql.connector in scripts. it is works in python interpreter. How come.

  • 1
    Impossible to answer. Short version: you coded it wrongly. An actual answer will not be possible. Please read up on a2hosting.com/kb/developer-corner/mysql/… for instance on how this works. You will need to expand this question if you expect an actual answer. – Rinzwind Jul 18 '19 at 16:28
0

There are a few possibilities as to what is wrong.

  • The script is running python2
  • The script is loading a different set of python packages than you expect:
    • /home/USER/.local/lib/python3.6/site-packages/mysql/connector
    • /usr/local/lib/python3.6/dist-packages/mysql/connector
    • ~/project_path/venv/lib/python3.6/dist-packages/mysql/connector

Make sure you installed mysql-connector in the same location as the script expects it. For instance, if your script is not running as your user, run the pip3 command as sudo to install it in /usr/local/lib.

Setting up virtual environments is the preferred way if you have multiple projects, each project can have it's own packages. Then in your script you would active the environment with source ~/project_path/venv/bin/activate in your script before running python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.