Snow Leopard 安装 Python MySQLdb 记录

本文详细记录了在MacOS环境下从下载到安装MySQL-Python模块的全过程,包括解压、配置环境变量、编译和安装等步骤,并展示了安装过程中遇到的问题及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 下载 mysql-python from sf.net

2. 解压,进入解压后的目录。

Input:
cd MySQL-python-1.2.3c1
python setup.py build

Output:
...
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.6-universal-2.6
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,'gamma',1) -D__version__=1.2.3c1 -I/Applications/MAMP/Library/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 -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
...

Input:
export C_INCLUDE_PATH=/usr/local/mysql/include/
export LIBRARY_PATH=/usr/local/mysql/lib/
python setup.py build

Output:
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 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc -arch x86_64 build/temp.macosx-10.6-universal-2.6/_mysql.o -L/Applications/MAMP/Library/lib/mysql -lmysqlclient_r -lz -lm -o build/lib.macosx-10.6-universal-2.6/_mysql.so
ld: warning: in /usr/local/mysql/lib/libmysqlclient_r.dylib, file was built for i386 which is not the architecture being linked (ppc)
ld: warning: in /usr/local/mysql/lib/libmysqlclient_r.dylib, file was built for i386 which is not the architecture being linked (x86_64)

Input:
sudo python setup.py install

Output:
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'
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
creating build/bdist.macosx-10.6-universal/egg
copying build/lib.macosx-10.6-universal-2.6/.DS_Store -> build/bdist.macosx-10.6-universal/egg
copying build/lib.macosx-10.6-universal-2.6/_mysql.so -> build/bdist.macosx-10.6-universal/egg
copying build/lib.macosx-10.6-universal-2.6/_mysql_exceptions.py -> build/bdist.macosx-10.6-universal/egg
creating build/bdist.macosx-10.6-universal/egg/MySQLdb
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/__init__.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/connections.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
creating build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/__init__.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/CLIENT.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/CR.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/ER.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/FLAG.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/constants/REFRESH.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb/constants
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/converters.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/cursors.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/release.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
copying build/lib.macosx-10.6-universal-2.6/MySQLdb/times.py -> build/bdist.macosx-10.6-universal/egg/MySQLdb
byte-compiling build/bdist.macosx-10.6-universal/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.macosx-10.6-universal/egg/MySQLdb/times.py to times.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.macosx-10.6-universal/egg/_mysql.py to _mysql.pyc
creating build/bdist.macosx-10.6-universal/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.macosx-10.6-universal/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.macosx-10.6-universal/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.macosx-10.6-universal/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.macosx-10.6-universal/egg/EGG-INFO
writing build/bdist.macosx-10.6-universal/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg' and adding 'build/bdist.macosx-10.6-universal/egg' to it
removing 'build/bdist.macosx-10.6-universal/egg' (and everything under it)
Processing MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg
Removing /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg
Copying MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg to /Library/Python/2.6/site-packages
Adding MySQL-python 1.2.3c1 to easy-install.pth file

Installed /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg
Processing dependencies for MySQL-python==1.2.3c1
Finished processing dependencies for MySQL-python==1.2.3c1

Input:
ipython

In [2]: import MySQLdb

In [3]: dir(MySQLdb)
Out[3]:
['BINARY',
'Binary',
'Connect',
'Connection',
'DATE',
'DATETIME',
'DBAPISet',
'DataError',
'DatabaseError',
'Date',
'DateFromTicks',
'Error',
'FIELD_TYPE',
'IntegrityError',
'InterfaceError',
'InternalError',
'MySQLError',
'NULL',
'NUMBER',
'NotSupportedError',
'OperationalError',
'ProgrammingError',
'ROWID',
'STRING',
'TIME',
'TIMESTAMP',
'Time',
'TimeFromTicks',
'Timestamp',
'TimestampFromTicks',
'Warning',
'__all__',
'__author__',
'__builtins__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__revision__',
'__version__',
'_mysql',
'apilevel',
'connect',
'connection',
'constants',
'debug',
'escape',
'escape_dict',
'escape_sequence',
'escape_string',
'get_client_info',
'paramstyle',
'release',
'result',
'server_end',
'server_init',
'string_literal',
'test_DBAPISet_set_equality',
'test_DBAPISet_set_equality_membership',
'test_DBAPISet_set_inequality',
'test_DBAPISet_set_inequality_membership',
'thread_safe',
'threadsafety',
'times',
'version_info']

In [4]:

安装成功!
内容概要:本文介绍了基于Python实现的SSA-GRU(麻雀搜索算法优化门控循环单元)时间序列预测项目。项目旨在通过结合SSA的全局搜索能力和GRU的时序信息处理能力,提升时间序列预测的精度和效率。文中详细描述了项目的背景、目标、挑战及解决方案,涵盖了从数据预处理到模型训练、优化及评估的全流程。SSA用于优化GRU的超参数,如隐藏层单元数、学习率等,以解决传统方法难以捕捉复杂非线性关系的问题。项目还提供了具体的代码示例,包括GRU模型的定义、训练和验证过程,以及SSA的种群初始化、迭代更新策略和适应度评估函数。; 适合人群:具备一定编程基础,特别是对时间序列预测和深度学习有一定了解的研究人员和技术开发者。; 使用场景及目标:①提高时间序列预测的精度和效率,适用于金融市场分析、气象预报、工业设备故障诊断等领域;②解决传统方法难以捕捉复杂非线性关系的问题;③通过自动化参数优化,减少人工干预,提升模型开发效率;④增强模型在不同数据集和未知环境中的泛化能力。; 阅读建议:由于项目涉及深度学习和智能优化算法的结合,建议读者在阅读过程中结合代码示例进行实践,理解SSA和GRU的工作原理及其在时间序列预测中的具体应用。同时,关注数据预处理、模型训练和优化的每个步骤,以确保对整个流程有全面的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值