Python 在通过 pip 安装 mysql-connector 期间无法找到 Protobuf 包含目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43029672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:27:06  来源:igfitidea点击:

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

pythonmysql-connector-python

提问by wei.lu

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

我拉了mysql-connector-python代码,运行时python ./setup.py build出现以下错误:

Unable to find Protobuf include directory.

pip install Protobufwas useless

pip install Protobuf没用

How can I solve this problem?

我怎么解决这个问题?

回答by yutaka2487

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

我发现这个错误是从 2.2.3 版本开始的。您可以使用 2.1.6 版避免此问题。

pip install mysql-connector==2.1.6

pip install mysql-connector==2.1.6

try above.

试试上面。

回答by Nuno Mariz

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.

从 2.2.3 开始,Connector/Python 使用 C++ 扩展与启用 X 插件的 MySQL 服务器连接,使用 Protobuf 作为数据交换格式。

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

因此,您需要设置 Protobuf 在系统上的安装位置(库、include 和 protoc 二进制路径)。

Requirements

要求

  • A C/C++ compiler, such as gcc
  • Protobuf C++ (version >= 2.6.0)
  • Python development files
  • AC/C++ 编译器,例如 gcc
  • Protobuf C++(版本 >= 2.6.0)
  • Python开发文件

Installation

安装

You have two options when using pip + pypi:

使用 pip + pypi 时有两种选择:

1) Set environment variables for MYSQLXPB_PROTOBUF_INCLUDE_DIR, MYSQLXPB_PROTOBUF_LIB_DIRand MYSQLXPB_PROTOC.

1) 为MYSQLXPB_PROTOBUF_INCLUDE_DIR,MYSQLXPB_PROTOBUF_LIB_DIR和设置环境变量MYSQLXPB_PROTOC

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

2) 添加--install-option以在使用 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.

重要提示:请记住,2.2.3 是一个开发版本。

回答by Long TRAN

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

我的 Ubuntu 16.04 也有这个问题,最后可以通过以下步骤安装 mysql-connector 2.2.3:

  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
    
  1. 通过 Ubuntu 包管理器安装这些包:

    sudo apt install libprotobuf-dev protobuf-compiler
    
  2. 设置这些环境变量:

    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. 通过 Python 包管理器安装 mysql-connector 包:

    pip install mysql-connector
    

Hope this helps.

希望这可以帮助。

回答by Brian

For some reason I noticed that pip install mysql-connectortried to install v2.2.3, which we don't want. Therefore, I specifically entered pip install mysql-connector==2.1.6and 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

出于某种原因,我注意到pip install mysql-connector尝试安装我们不想要的 v2.2.3。因此,我特地输入pip install mysql-connector==2.1.6并安装它没有错误。另请注意,我使用的是运行 python 3.6.1 的 virtualenv。我在那里安装了它。这是有关安装对我有帮助的特定 python 模块的文档。https://docs.python.org/3/installing/index.html

回答by Madhu Venkat

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

我在WIN 7 64 位,python 27。这个命令对我有用,似乎最合适,特别是当v2.2.3是一个开发版本时。

pip install mysql-connector==2.1.4

回答by Madhu Venkat

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

请注意,2.1.6 连接器NoneType在连接到 Django 1.11 时失败并显示错误。已在 2.1.7 中修复。

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

阅读:mysql-connector-python 无法与 django 1.11 一起使用

回答by Maggyero

On macOS, if you use Homebrew:

在 macOS 上,如果您使用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

回答by Ricardo Ramírez

To install protobuf with mac ports, I did the following

要使用 mac 端口安装 protobuf,我执行了以下操作

Installing protobuf:

安装protobuf:

port install protobuf-cpp

port install protobuf-cpp

Declare where is protobuf

声明protobuf在哪里

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

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

pip install mysql-connector