Unable to find Protobuf include directory during install mysql-connector over pip
Asked Answered
P

8

39

I pulled mysql-connector-python code and when I run python ./setup.py build I get the following error:

Unable to find Protobuf include directory.

pip install Protobuf was useless

How can I solve this problem?

Prenomen answered 26/3, 2017 at 13:58 Comment(1)
I also had a same error message when I tried to install mysql-connector 2.2.3 (not mysql-connector-python) by pip. 2.2.3 is development release. And I could install 2.1.4. How about trying another version?Adim
V
108

I found that this error occurs since version 2.2.3. You can avoid this issue using version 2.1.6.

pip install mysql-connector==2.1.6

try above.

Vday answered 28/3, 2017 at 5:5 Comment(0)
M
12

As of 2.2.3, Connector/Python uses a C++ extension that interfaces with a MySQL server with the X plugin enabled, using Protobuf as data interchange format.

So, you need to set up where Protobuf is installed on your system (the library, include and protoc binary paths).

Requirements

  • A C/C++ compiler, such as gcc
  • Protobuf C++ (version >= 2.6.0)
  • Python development files

Installation

You have two options when using pip + pypi:

1) Set environment variables for MYSQLXPB_PROTOBUF_INCLUDE_DIR, MYSQLXPB_PROTOBUF_LIB_DIR and MYSQLXPB_PROTOC.

2) Add --install-option to set these options when using pip:

shell> python install mysql-connector --install-option='--with-protobuf-include-dir=<path>' --install-option='--with-protobuf-lib-dir=<path>' --install-option='--with-protoc=<path>'

Important: Keep in mind that 2.2.3 is a development release.

Maurita answered 28/3, 2017 at 10:16 Comment(0)
A
9

I also have this issue on my Ubuntu 16.04 and finally can install mysql-connector 2.2.3 with the following steps:

  1. Install these packages via the Ubuntu package manager:

    sudo apt install libprotobuf-dev protobuf-compiler
    
  2. Set these environment variables:

    export MYSQLXPB_PROTOC=/usr/bin/protoc
    export MYSQLXPB_PROTOBUF_INCLUDE_DIR=/usr/include/google/protobuf
    export MYSQLXPB_PROTOBUF_LIB_DIR=/usr/lib/x86_64-linux-gnu
    
  3. Install the mysql-connector package via the Python package manager:

    pip install mysql-connector
    

Hope this helps.

Abbottson answered 2/8, 2017 at 1:47 Comment(1)
also make sure you have gcc-4.9 installed (it's hardcoded in the wheel)Vexation
T
3

For some reason I noticed that pip install mysql-connector tried to install v2.2.3, which we don't want. Therefore, I specifically entered pip install mysql-connector==2.1.6 and it installed without error. Please note too that I am using a virtualenv running python 3.6.1. I installed it there. Here is documentation on installing specific python modules that helped me. https://docs.python.org/3/installing/index.html

Thine answered 25/7, 2017 at 15:59 Comment(0)
T
1

I am on WIN 7 64-bit, python 27. This command works for me and seems most appropriate, particularly when v2.2.3 is a development version.

pip install mysql-connector==2.1.4
Tweezers answered 31/8, 2017 at 15:47 Comment(0)
E
0

To install protobuf with mac ports, I did the following

Installing protobuf:

port install protobuf-cpp

Declare where is protobuf

export MYSQLXPB_PROTOBUF_LIB_DIR=/opt/local/lib export MYSQLXPB_PROTOC=/opt/local/bin/protoc export MYSQLXPB_PROTOBUF_INCLUDE_DIR=/opt/local/include

Installing the connector

pip install mysql-connector

Emmott answered 3/8, 2017 at 10:34 Comment(0)
N
0

Please know that 2.1.6 Connector fails with NoneType error when connecting to Django 1.11. Fixed in 2.1.7.

Read: mysql-connector-python fails to work with django 1.11.

Nodab answered 7/11, 2017 at 10:57 Comment(0)
M
0

On macOS, if you use Homebrew:

$ brew install protobuf
$ export MYSQLXPB_PROTOC=/usr/local/opt/protobuf/bin/protoc
$ export MYSQLXPB_PROTOBUF_INCLUDE_DIR=/usr/local/opt/protobuf/include/
$ export MYSQLXPB_PROTOBUF_LIB_DIR=/usr/local/opt/protobuf/lib/
$ pip3 install mysql-connector
Mudstone answered 11/1, 2018 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.