Проблемы с настройкой модуля MySQLdb

Я вытаскиваю свои волосы здесь, пытаясь настроить MySQLdb на моем Mac, чтобы подключиться к удаленному серверу MySQL.

  • Я установил последние клиентские библиотеки C MySQL
  • Я установил XCode 4
  • Я наивно пытался установить модуль перед установкой XCode или клиентских библиотек

Я пытаюсь настроить модуль, выполнив следующие команды в терминале:

$sudo python setup.py build

$sudo python setup.py install

Обе эти команды выходят из строя с аналогичными сообщениями об ошибках. Вот первая трассировка стека:

running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -fno-omit-frame-pointer -pipe
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/include/mysql/my_config.h:1151:1: warning: "WORDS_BIGENDIAN" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:1014:1: warning: this is the location of the previous definition
_mysql.c:2888: fatal error: error writing to -: Broken pipe
compilation terminated.
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1027:2: warning: #warning defining SIZEOF_CHARP = 8
/usr/include/mysql/my_config.h:1041:2: warning: #warning defining SIZEOF_LONG = 8
lipo: can't open input file: /var/tmp//ccU6bipK.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

И вот трассировка стека для второй команды:

running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-universal/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -fno-omit-frame-pointer -pipe
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/include/mysql/my_config.h:1151:1: warning: "WORDS_BIGENDIAN" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:1014:1: warning: this is the location of the previous definition
_mysql.c:2888: fatal error: error writing to -: Broken pipe
compilation terminated.
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1027:2: warning: #warning defining SIZEOF_CHARP = 8
/usr/include/mysql/my_config.h:1041:2: warning: #warning defining SIZEOF_LONG = 8
lipo: can't open input file: /var/tmp//cchhckGP.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

Я занимаюсь этим уже несколько дней, и это начинает приводить меня в бешенство. Любая помощь будет принята с благодарностью!

Ответ 1

Вы настроились на головные боли, установив новую и перспективную Xcode 4, а не последнюю версию Xcode 3, что и было выпущено Mac OS X 10.6. Непосредственная проблема, с которой вы сталкиваетесь, заключается в том, что Python пытается создать модули расширения C с той же конфигурацией, что и сам Python. Для 10.6, который включает в себя три архитектуры: i386, x86_64 и ppc (для совместимости с программами, основанными на более ранних системах). По-видимому, Xcode 4 удалил поддержку для построения арки ppc. Вы можете легко обойти эту проблему, используя переменную среды ARCHFLAGS, которая используется для переопределения параметров арки, используемых Python Distutils при создании модулей расширения. Попробуйте сделать что-то вроде этого (непроверено, поскольку у меня нет Xcode 4):

sudo bash
export ARCHFLAGS='-arch i386 -arch x86_64'
rm -r build
python setup.py build
python setup.py install

Лучшим решением, как рекомендовано в других разделах, является попытка не пытаться установить MySQLdb на 10.6 с помощью системы Python и двоичных установщиков MySQL. Скорее, используйте полное решение, установив все через диспетчер пакетов, например MacPorts.

Ответ 2

когда я запускаю команду, я создал ошибку

python setup.py build

здание '_mysql' расширение, создающее build/temp.macosx-10.6-intel-2.7 clang -fno-strict-aliasing -fno-common -dynamic -isysroot/Developer/SDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -Dversion_info = (1,2,3, 'final', 0 ) -D_version_ = 1.2.3 -I/Приложения/XAMPP/xamppfiles/include/mysql -I/Library/Frameworks/Python.framework/Версии/2.7/include/python2.7 -c _mysql.c -o build/temp. macosx-10.6-intel-2.7/_mysql.o -mmacosx-version-min = 10.4 -arch i386 -arch ppc -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL clang: warning: не использовать компилятор clang для архитектуры "powerpc" _mysql.c: 36: 10: фатальная ошибка: файл "my_config.h" не найден

включить "my_config.h"

Ответ 3

Есть другой способ, который я только решил решить. Я столкнулся с той же проблемой, что и вы, и моя версия python - 2.7.4 и Xcode 4. Возможно, вы только что получили питон из 32 бит, как и я. Поэтому я изменил его на 2.7.5x64bit, тогда проблем не должно быть.