If loading via pip install mysql-connector and leads an error Unable to find Protobuf include directory then this would be useful pip install mysql-connector==2.1.4
mysql-connector is obsolete, so use pip install mysql-connector-python. Same here
Β» pip install mysql-connector-python
If loading via pip install mysql-connector and leads an error Unable to find Protobuf include directory then this would be useful pip install mysql-connector==2.1.4
mysql-connector is obsolete, so use pip install mysql-connector-python. Same here
To install the official MySQL Connector for Python, please use the name mysql-connector-python:
pip install mysql-connector-python
Some further discussion, when we pip search for mysql-connector at this time (Nov, 2018), the most related results shown as follow:
$ pip search mysql-connector | grep ^mysql-connector
mysql-connector (2.1.6) - MySQL driver written in Python
mysql-connector-python (8.0.13) - MySQL driver written in Python
mysql-connector-repackaged (0.3.1) - MySQL driver written in Python
mysql-connector-async-dd (2.0.2) - mysql async connection
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python-dd (2.0.2) - MySQL driver written in Python
mysql-connector (2.1.6)is provided on PyPI when MySQL didn't provide their officialpip installon PyPI at beginning (which was inconvenient). But it is a fork, and is stopped updating, sopip install mysql-connectorwill install this obsolete version.
And now
mysql-connector-python (8.0.13)on PyPI is the official package maintained by MySQL, so this is the one we should install.
sudo apt-get install python3-mysql.connector
or
pip3 install mysql-connector
this will install mysql.connector for python3 on ubuntu
Ah! The problem you seem to be facing is you can't create virtualenv with python3.
And to install dependencies for python3 environment you run pip3 install package-name
Follow these steps for creating virtualenv in python3 environment:
virtualenv -p /usr/bin/python3 yourenv
source yourenv/bin/activate
pip3 install mysql-connector
There are two ways to install MySQL connector. The second way is preferred.
1. MySQL Installer
This is Oracle's product installer. The problem is that it is outdated. It is only aware of Python version 3.6, and nothing newer. To install for a newer version of Python, use option 2.
2. Python package manager, pip
The Python package manager comes with Python, called pip. It downloads the package from the PyPI repository and installs it in an automatic location based on what version of Python (or what virtual copy) you use to install it. The package that you want is mysql-connector-python. In fact, the official documentation says this is the recommended method for installing the MySQL Connector.
For example, on Windows, open up the Command Prompt (cmd.exe) by searching in the Start Menu. Navigate to the directory where pip is installed. Or make sure that pip's directory is included in the $PATH variable (which you can edit by searching for "PATH" in the Start Menu).
The command prompt will show you this:
PS C:\Users\Ryan>
except instead of my username, it'll show your username, or the path you navigated to after you found pip, like "C:\blah\blah". Then use this command...
Input:
pip install mysql-connector-python
It downloads and installs it.
Results:
PS C:\Users\Ryan> pip install mysql-connector-python
Collecting mysql-connector-python
Downloading https://files.pythonhosted.org/packages/2d/65/3fc902c0f7635912800c6b935313b99b9d4426419ef7ba04f76231b24923/mysql_connector_python-8.0.12-py2.py3-none-any.whl (300kB)
100% |ββββββββββββββββββββββββββββββββ| 307kB 1.1MB/s
Collecting protobuf>=3.0.0 (from mysql-connector-python)
Downloading https://files.pythonhosted.org/packages/77/78/a7f1ce761e2c738e209857175cd4f90a8562d1bde32868a8cd5290d58926/protobuf-3.6.1-py2.py3-none-any.whl (390kB)
100% |ββββββββββββββββββββββββββββββββ| 399kB 1.8MB/s
Requirement already satisfied: setuptools in c:\users\ryan\appdata\local\programs\python\python37\lib\site-packages (from protobuf>=3.0.0->mysql-connector-python) (40.4.3)
Collecting six>=1.9 (from protobuf>=3.0.0->mysql-connector-python)
Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six, protobuf, mysql-connector-python
Successfully installed mysql-connector-python-8.0.12 protobuf-3.6.1 six-1.11.0
Afterward, you can make sure it is installed by displaying all packages that have been installed by you (not including standard libraries, which come with Python):
Input:
PS C:\Users\Ryan> pip list
Results:
Package Version
---------------------- -------
mysql-connector-python 8.0.12
pip 18.0
protobuf 3.6.1
setuptools 40.4.3
six 1.11.0
To check if you installed it to the right version of Python, use pip -V. To make sure you installed it to the right copy (virtual or original), look at the file path where the package was installed:
PS C:\Users\Ryan> pip -V
Results:
pip 18.0 from c:\users\ryan\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)
For example, in my system, it shows python37 in the folder path, so it installed it to the original Python 3.7.0 installation I have, instead of an older version or virtual environment (conda or virtualenv, etc).
To check the version using the Python executable, instead of pip:
PS C:\Users\Ryan> py -V
Python 3.7.0
If you need to install it to an older or newer Python version than the default installation, insert the version number as an option (aka. "switch") in the command, using -. For example, to select version 3.6:
py -3.6 -m pip install mysql-connector-python
The - works on both Windows and Unix-like OSs.
mysqlclient supports python3.7 officially, you can find it here :
https://pypi.python.org/pypi/mysqlclient
1)you can download , PyMySQL 0.9.2
2)extract & copy the folder pymysql into the python Lib folder
3)and for connection you can do like this(make a file for example freeman.py):
#!/usr/bin/env python
import pymysql
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='freemanDB')
cur = conn.cursor()
cur.execute("SELECT * FROM users")
print(cur.description)
print()
for row in cur:
print(row)
cur.close()
conn.close()