How to load a package on the specified map?

I am only the beginner. I want to use the MySql database in my Python program on Windows 11 with the python version 3.10.
I have to use the command ‘import connect’, but I do not know how to download and install the package ‘connect’ on the path 'C:\Program Files\Python' instead on the map ‘users.…\AppData\Roaming\Python.…’.

My Windows path contains:
PATH=C:\Program Files\Python\Scripts;C:\Program Files\Python;…

1 Like

I’d advise to keep Python (in C:\Program Files\Python) and Python packages (in users.…\AppData\Roaming\Python.…) separate. Python (the interpreter) uses a different search path for packages than Windows (the OS) uses for programs.

For MySQL, you need to

If you want to be a little more ambitious, installing in a virtual environment (venv, see venv — Creation of virtual environments — Python 3.10.5 documentation) makes the setup more and future-proof by installing the package on a per-project basis.

Good luck!

Thank you very much for your clear explanation.

I have used the command ’ by pip install mysql-connector-pythonsuccessfully. That module is apparently place in the path ‘C:\Users.…\AppData\Roaming\Python\Python310\site-packages’.

I have adapted my systempath as follows:
PATH=C:\Program Files\Python\Scripts;C:\Program Files\Python;C:\Users.…\AppData\Roaming\Python\Python310\site-packages;C:\Users.…\AppData\Roaming\Python\Python310\Scripts;C:\WINDOWS\system32;…

Then I tried to run my Python program containing the command ‘import mysql.connector’. Unfortunately I got the error: No module named ‘mysql’!?

What should I have done wrongly?

Changing the Windows %PATH% should not be necessary. Python looks in sys.path to locate modules to import. Check that one for your module.

Look up the documentation sys — System-specific parameters and functions — Python 3.10.5 documentation for details (I.e. how to set if not included automatically).

My code ‘import mysql’ does work fine, however after my follwing codes have been processed successfully:
xxx = # i.e. empty list
xxx.append(‘C:\Program Files\Python\DLLs’)
xxx.append(‘C:\Program Files\Python\Lib’)
xxx.append(‘C:\Program Files\Python’)
xxx.append(‘C:\Program Files\Python\lib\site-packages’)
sys.path = xxx.copy()

Now I wonder me how i can create ‘PYTHONPATH’, so that it will be processed automaticcaly without my previous cumbersome and unnecessary codes.

At last I wonder me why mysql does not support UTF8, because when my code ‘mydb = mysql.connector.connect(host=‘localhost’, user=’…‘, password=’…') has been processed, I got the error as follows:
<class ‘mysql.connector.errors.ProgrammingError’>: Character set ‘utf8’ unsupported

What to do now?

I wonder me, whether that utf8 problem cab be caused by my mysql database being set up by the phpMyAdmin or Apache web server with MariaDB (i.e. MySQL) and PHP. If so, what have I to do.

After removal and reinstalation of python and mysql system the usage of the utf8 is surprised solved!