在macoslion上安装oursql成功,但在python中导入失败。**为什么?**

2024-09-30 01:24:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我按照安装说明在macosx上安装了oursql

sudo pip install oursql

告诉我,它找不到mysql_config我(用locate mysql_config找到它)告诉它在哪里找到它

^{pr2}$

出于可读性的原因,我在底部添加了终端输出。在那之后,我在终端中启动了python(在macoslion上现在是python2.7,…)并做到了

>>> import oursql

但是python一直告诉我:

>>> import oursql
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/oursql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/oursql.so
  Reason: image not found

我错过了什么?有什么建议吗?在


pip安装的终端输出:

Downloading/unpacking oursql
  Downloading oursql-0.9.2.tar.bz2 (113Kb): 113Kb downloaded
  Running setup.py egg_info for package oursql

Installing collected packages: oursql
  Running setup.py install for oursql
    skipping 'oursqlx/oursql.c' Cython extension (up-to-date)
    building 'oursql' extension
    /usr/local/mysql-5.5.14-osx10.6-x86_64/bin/mysql_config --cflags
    llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c oursqlx/oursql.c -o build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o -I/usr/local/mysql-5.5.14-osx10.6-x86_64/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64
    oursqlx/oursql.c: In function ‘__pyx_pf_6oursql_10Connection___cinit__’:
    oursqlx/oursql.c:4630: warning: implicit conversion shortens 64-bit value into a 32-bit value
    oursqlx/oursql.c: In function ‘__pyx_pf_6oursql_10_Statement_execute’:
    oursqlx/oursql.c:10219: warning: implicit conversion shortens 64-bit value into a 32-bit value
    oursqlx/oursql.c: In function ‘__pyx_pf_6oursql_16_DBAPITypeObject___richcmp__’:
    oursqlx/oursql.c:17597: warning: implicit conversion shortens 64-bit value into a 32-bit value
    llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c oursqlx/compat.c -o build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o -I/usr/local/mysql-5.5.14-osx10.6-x86_64/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64
    /usr/local/mysql-5.5.14-osx10.6-x86_64/bin/mysql_config --libs
    llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o -o build/lib.macosx-10.7-intel-2.7/oursql.so -L/usr/local/mysql-5.5.14-osx10.6-x86_64/lib -lmysqlclient -lpthread
    ld: warning: ignoring file build/temp.macosx-10.7-intel-2.7/oursqlx/oursql.o, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: ignoring file build/temp.macosx-10.7-intel-2.7/oursqlx/compat.o, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: ignoring file /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

Successfully installed oursql
Cleaning up...

Tags: buildosusrlocalmysqlcommonx86macosx
3条回答

我在寻找在OSX 10.10.5上安装我们的SQL的解决方案时遇到了这个问题。我以前用brew brew install mysql安装了mysql。对于那些希望在yosemite上安装我们的SQL的用户,以下是对我有用的方法:

1)手动下载包。请参阅链接here。在

2)在您喜欢的文本编辑器中打开oursql/oursql-0.9.3.1/oursqlx/_exceptions.c

3)注释最后一个“默认值”,应该如下所示:

    /*default:
        if (err >= ER_ERROR_FIRST && err <= ER_ERROR_LAST)
            return _oursqlx_ProgrammingError;
        else if (err > CR_MIN_ERROR && err < CR_MAX_ERROR)
            return _oursqlx_InterfaceError;*/

4)现在再次尝试运行安装程序:

^{pr2}$

这起作用了:

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"

如果不想安装完整的MySQL,可以使用MySQL-connector-c编译我们的sql

下载mysql-connector-c,解压缩并安装:

wget http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-osx10.5-x86-64bit.tar.gz/from/http://cdn.mysql.com/
tar -xvf mysql-connector-c-6-1.0.2-osx10.5-x86-64bit.tar
cd mysql-connector-c-6.0.2-osx10.5-x86-64bit
sudo cp bin/* /usr/local/bin/
sudo cp lib/* /usr/local/lib/
sudo cp -r include/* /usr/local/include/

下载并解压缩oursql:

^{pr2}$

编译我们的SQL:

cd oursql-0.9.3
sudo python setup.py build_ext

这已经过验证,可以与OSX 10.8.2、Xcode 4.5.2和Python3.2.3一起使用

相关问题 更多 >

    热门问题