【问题标题】:Unable to find Protobuf include directory during install mysql-connector over pip在通过 pip 安装 mysql-connector 期间找不到 Protobuf 包含目录
【发布时间】:2017-08-19 04:08:55
【问题描述】:

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

Unable to find Protobuf include directory.

pip install Protobuf 没用

我该如何解决这个问题?

【问题讨论】:

  • 当我尝试通过 pip 安装 mysql-connector 2.2.3(不是 mysql-connector-python)时,我也收到了同样的错误消息。 2.2.3 是开发版本。我可以安装 2.1.4。试试其他版本怎么样?

标签: python mysql-connector-python


【解决方案1】:

在 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

【讨论】:

    【解决方案2】:

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

    阅读:mysql-connector-python fails to work with django 1.11

    【讨论】:

      【解决方案3】:

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

      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
        

      希望这会有所帮助。

      【讨论】:

      • 还要确保你安装了 gcc-4.9(它是硬编码在轮子里的)
      【解决方案4】:

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

      pip install mysql-connector==2.1.6

      上面试试。

      【讨论】:

        【解决方案5】:

        我使用的是 WIN 7 64-bit,python 27。这个命令对我有用,似乎最合适,尤其是当 v2.2.3 是开发版本时。

        pip install mysql-connector==2.1.4
        

        【讨论】:

          【解决方案6】:

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

          安装 protobuf:

          port install protobuf-cpp

          声明protobuf在哪里

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

          安装连接器

          pip install mysql-connector

          【讨论】:

            【解决方案7】:

            出于某种原因,我注意到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

            【讨论】:

              【解决方案8】:

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

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

              要求

              • C/C++ 编译器,例如 gcc
              • Protobuf C++(版本 >= 2.6.0)
              • Python 开发文件

              安装

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

              1) 为MYSQLXPB_PROTOBUF_INCLUDE_DIRMYSQLXPB_PROTOBUF_LIB_DIRMYSQLXPB_PROTOC 设置环境变量。

              2) 使用 pip 时添加--install-option 设置这些选项:

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

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2015-10-23
                • 1970-01-01
                • 2016-12-11
                • 2016-02-11
                • 2017-12-03
                • 2014-03-07
                • 2018-05-24
                • 2013-07-21
                相关资源
                最近更新 更多