I installed mysql.connector in python3 using pip3. but can not import mysql.connector in scripts. it is works in python interpreter. How come.
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:
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.