繁体   English   中英

在pip安装mysql-connector期间无法找到Protobuf include目录

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

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

Unable to find Protobuf include directory.

pip install Protobuf没用

我怎么解决这个问题?

我发现从版本2.2.3开始发生此错误。 您可以使用版本2.1.6来避免此问题。

pip install mysql-connector==2.1.6

试试上面。

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

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

要求

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

安装

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

1)为MYSQLXPB_PROTOBUF_INCLUDE_DIRMYSQLXPB_PROTOBUF_LIB_DIRMYSQLXPB_PROTOC设置环境变量。

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>'

重要提示:请记住2.2.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 

希望这可以帮助。

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

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

pip install mysql-connector==2.1.4

要使用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

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

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

在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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM