我一直尝试使用 pip 安装 oursql(7.1.0,我使用sudo easy_install pip
提供的版本安装它,因为对于我的目的来说python-pip
它太旧了)通过运行:
sudo pip install oursql
但这会返回错误:
Collecting oursql
Using cached oursql-0.9.3.1.tar.bz2
Building wheels for collected packages: oursql
Running setup.py bdist_wheel for oursql
Complete output from command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-8AI16g/oursql/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpAakYx7pip-wheel-:
running bdist_wheel
running build
running build_ext
skipping 'oursqlx/oursql.c' Cython extension (up-to-date)
warning: no usable mysql_config and no _winreg module to try; hopefully you have usable CFLAGS/LDFLAGS set.
building 'oursql' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/oursqlx
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c oursqlx/oursql.c -o build/temp.linux-x86_64-2.7/oursqlx/oursql.o
In file included from oursqlx/oursql.c:235:0:
oursqlx/compat.h:13:19: fatal error: mysql.h: No such file or directory
#include "mysql.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for oursql
Failed to build oursql
Installing collected packages: oursql
Running setup.py install for oursql
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-8AI16g/oursql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-z5NtR4-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
skipping 'oursqlx/oursql.c' Cython extension (up-to-date)
warning: no usable mysql_config and no _winreg module to try; hopefully you have usable CFLAGS/LDFLAGS set.
building 'oursql' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c oursqlx/oursql.c -o build/temp.linux-x86_64-2.7/oursqlx/oursql.o
In file included from oursqlx/oursql.c:235:0:
oursqlx/compat.h:13:19: fatal error: mysql.h: No such file or directory
#include "mysql.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-8AI16g/oursql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-z5NtR4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-8AI16g/oursql
我曾尝试过本指南,但我完全不知道我应该用这个MYSQL_CONFIG
变量做什么,因为我不知道应该将它设置为什么。我还尝试运行:sudo easy_install oursql
安装 oursql,但它也失败了,给出:
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py:2512:
PEP440Warning: 'python-apt (0.9.3.11build1)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
PEP440Warning,
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py:2512: PEP440Warning: 'PyECLib (1.0.5m)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
PEP440Warning,
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py:2512: PEP440Warning: 'pygame (1.9.1release)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
PEP440Warning,
Searching for oursql
Reading https://pypi.python.org/simple/oursql/
Reading http://launchpad.net/oursql
Best match: oursql 0.9.3.1
Downloading https://pypi.python.org/packages/source/o/oursql/oursql-0.9.3.1.zip#md5=ad599ea2d95fc695df7195e9801b45c2
Processing oursql-0.9.3.1.zip
Writing /tmp/easy_install-gejSuT/oursql-0.9.3.1/setup.cfg
Running oursql-0.9.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-gejSuT/oursql-0.9.3.1/egg-dist-tmp-N9kmGB
warning: no usable mysql_config and no _winreg module to try; hopefully you have usable CFLAGS/LDFLAGS set.
In file included from oursqlx/oursql.c:235:0:
oursqlx/compat.h:13:19: fatal error: mysql.h: No such file or directory
#include "mysql.h"
^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
答案1
我自己找到了解决方案,我遵循的指南让我相信 pip 会为我完成所有工作(即安装所有必要的依赖项),但我需要安装 MySQL Connector C++ 库(Ubuntu 包名称:)libmysqlcppconn-dev
。所以我运行sudo apt-get install libmysqlcppconn-dev
安装这个包,然后sudo pip install oursql
运行没有错误。所以 Timo 的评论是正确的。
答案2
在 macOS 中安装 oursql。
因此,这是在 macOS 中正确安装 oursql 的标准解决方案。
brew install [email protected]
现在,请按照安装结束时给出的所有说明进行操作。
要运行安全安装(设置密码等),您需要转到此处并运行/usr/local/[email protected]/bin/mysql_secure_installation
现在,一旦我们安装了 mysql,就会有一些我们自己包的依赖项,例如mysql-client
。您可以使用以下命令安装它:
brew install mysql-client
安装后,请按照安装结束时给出的安装说明进行操作。
不要忘记在这里重新加载 bash。source ~/.bash_profile
现在,通过以下方式重新启动 mysqlbrew service restart mysql
现在,最后先用 pip 安装 mysqlclient,然后安装 oursql。
pip install mysqlclient
pip install oursql
都好!
答案3
oursql
我在虚拟环境中安装时刚刚遇到了类似的问题。
我的输出包含与下面这部分类似的错误(来自问题):
oursqlx/compat.h:13:19: fatal error: mysql.h: No such file or directory
#include "mysql.h"
^
compilation terminated.
这让我找到了可接受答案中的解决方案这个 stackoverflow 问题。
sudo apt install libmysqlclient-dev
解决了我的问题。