在 Windows 上使用 PIP 编译 mysql-python
Posted
技术标签:
【中文标题】在 Windows 上使用 PIP 编译 mysql-python【英文标题】:Compiling mysql-python on Windows with PIP 【发布时间】:2014-08-24 12:17:12 【问题描述】:所以我在我的 Windows 7 笔记本电脑上安装了 Python 2.7 和 setuptools。我还安装了 Visual Studio 2008 Express 和带有开发工具的 mysql。
我正在尝试通过 pip 安装 mysql-python,例如:
pip install mysql-python
我收到链接错误:
Creating library build\temp.win32-2.7\Release\_mysql.lib and object build\temp.win32-2.7\Release\_mysql.exp
_mysql.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function __mysql_Exception
_mysql.obj : error LNK2019: unresolved external symbol _mysql_errno@4 referenced in function __mysql_Exception
_mysql.obj : error LNK2019: unresolved external symbol _mysql_server_init@12 referenced in function __mysql_server_init
_mysql.obj : error LNK2019: unresolved external symbol _mysql_server_end@0 referenced in function __mysql_server_end
_mysql.obj : error LNK2019: unresolved external symbol _mysql_thread_safe@0 referenced in function __mysql_thread_safe
_mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_fields@4 referenced in function __mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_num_fields@4 referenced in function __mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_field_count@4 referenced in function __mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function __mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_use_result@4 referenced in function __mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function __mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_ssl_set@24 referenced in function __mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_options@12 referenced in function __mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function __mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function __mysql_ConnectionObject_close
_mysql.obj : error LNK2019: unresolved external symbol _mysql_affected_rows@4 referenced in function __mysql_ConnectionObject_affected_rows
_mysql.obj : error LNK2019: unresolved external symbol _mysql_debug@4 referenced in function __mysql_debug
_mysql.obj : error LNK2019: unresolved external symbol _mysql_dump_debug_info@4 referenced in function __mysql_ConnectionObject_dump_debug_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_autocommit@8 referenced in function __mysql_ConnectionObject_autocommit
_mysql.obj : error LNK2019: unresolved external symbol _mysql_commit@4 referenced in function __mysql_ConnectionObject_commit
_mysql.obj : error LNK2019: unresolved external symbol _mysql_rollback@4 referenced in function __mysql_ConnectionObject_rollback
_mysql.obj : error LNK2019: unresolved external symbol _mysql_next_result@4 referenced in function __mysql_ConnectionObject_next_result
_mysql.obj : error LNK2019: unresolved external symbol _mysql_set_server_option@8 referenced in function __mysql_ConnectionObject_set_server_option
_mysql.obj : error LNK2019: unresolved external symbol _mysql_sqlstate@4 referenced in function __mysql_ConnectionObject_sqlstate
_mysql.obj : error LNK2019: unresolved external symbol _mysql_warning_count@4 referenced in function __mysql_ConnectionObject_warning_count
_mysql.obj : error LNK2019: unresolved external symbol _mysql_escape_string@12 referenced in function __mysql_escape_string
_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_escape_string@16 referenced in function __mysql_escape_string
_mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_lengths@4 referenced in function __mysql_row_to_tuple
_mysql.obj : error LNK2019: unresolved external symbol __imp__strncpy referenced in function __mysql_row_to_dict
_mysql.obj : error LNK2019: unresolved external symbol __imp__strncat referenced in function __mysql_row_to_dict
_mysql.obj : error LNK2019: unresolved external symbol _memset referenced in function __mysql_row_to_dict_old
_mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function __mysql__fetch_row
_mysql.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function __mysql_ResultObject_fetch_row
_mysql.obj : error LNK2019: unresolved external symbol _mysql_change_user@16 referenced in function __mysql_ConnectionObject_change_user
_mysql.obj : error LNK2019: unresolved external symbol _mysql_character_set_name@4 referenced in function __mysql_ConnectionObject_character_set_name
_mysql.obj : error LNK2019: unresolved external symbol _mysql_set_character_set@8 referenced in function __mysql_ConnectionObject_set_character_set
_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_character_set_info@8 referenced in function __mysql_ConnectionObject_get_character_set_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_client_info@0 referenced in function __mysql_get_client_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_host_info@4 referenced in function __mysql_ConnectionObject_get_host_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_proto_info@4 referenced in function __mysql_ConnectionObject_get_proto_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_server_info@4 referenced in function __mysql_ConnectionObject_get_server_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_info@4 referenced in function __mysql_ConnectionObject_info
_mysql.obj : error LNK2019: unresolved external symbol _mysql_insert_id@4 referenced in function __mysql_ConnectionObject_insert_id
_mysql.obj : error LNK2019: unresolved external symbol _mysql_kill@8 referenced in function __mysql_ConnectionObject_kill
_mysql.obj : error LNK2019: unresolved external symbol _mysql_ping@4 referenced in function __mysql_ConnectionObject_ping
_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_query@12 referenced in function __mysql_ConnectionObject_query
_mysql.obj : error LNK2019: unresolved external symbol _mysql_select_db@8 referenced in function __mysql_ConnectionObject_select_db
_mysql.obj : error LNK2019: unresolved external symbol _mysql_shutdown@8 referenced in function __mysql_ConnectionObject_shutdown
_mysql.obj : error LNK2019: unresolved external symbol _mysql_stat@4 referenced in function __mysql_ConnectionObject_stat
_mysql.obj : error LNK2019: unresolved external symbol _mysql_thread_id@4 referenced in function __mysql_ConnectionObject_thread_id
_mysql.obj : error LNK2019: unresolved external symbol __imp__sprintf referenced in function __mysql_ConnectionObject_repr
_mysql.obj : error LNK2019: unresolved external symbol _mysql_data_seek@12 referenced in function __mysql_ResultObject_data_seek
_mysql.obj : error LNK2019: unresolved external symbol _mysql_row_seek@8 referenced in function __mysql_ResultObject_row_seek
_mysql.obj : error LNK2019: unresolved external symbol _mysql_row_tell@4 referenced in function __mysql_ResultObject_row_seek
_mysql.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function __mysql_ResultObject_dealloc
LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12
build\lib.win32-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\link.exe' failed with exit status 1120
任何想法如何解决这个问题?谢谢
【问题讨论】:
看看这些:***.com/questions/9951260/…***.com/questions/18296525/…***.com/a/12590280/3755171 链接的解决方案都不能解决问题。 您必须从源代码安装是否有特殊原因?在 Windows 上以预编译的二进制形式安装基于 C 的模块(例如这个)更为典型,例如从pypi.python.org/pypi/MySQL-python/1.2.5 下载并安装。您应该从源代码安装的唯一时间是如果您想破解 C 代码等。 【参考方案1】:我遇到了同样的问题和完全相同的错误。我不知道为什么,但是
pip install Mysql-python
报错。 但是当我尝试
easy_install Mysql-python
它起作用了。我不知道为什么,但它确实起作用了,但很想知道为什么。
【讨论】:
【参考方案2】:检查两者都是 32 位 或 64 位,并且它们之间没有不匹配。当我遇到这个问题时,是因为我安装了 64 位 Python,但安装了 32 位 MySQL。因此,pip 安装程序找不到要链接的匹配二进制文件,并出现此消息失败。解决问题只需在顶部安装 32 位 Python,一切正常。
请注意,也可以将 MySQL 更新为 64 位,但目前 MySQL 的安装程序似乎只有 32 位。您可以通过从 MySQL 官方网站下载的 .zip 文件进行安装,尽管其中包含 64 位二进制文件。
要找出你安装了哪些:
对于 Python,只需转到命令行并输入python
。它应该告诉你什么版本,如果它是一个 32 位或 64 位安装像这样
对于 MySQL,最简单的方法可能是安装在哪个文件夹中。如果安装到Win32 上的 Python 2.7.10(默认,2015 年 5 月 23 日,09:40:32)[MSC v.1500 32 位(英特尔)]
Program Files/
,则为 64 位,但如果安装到 Program Files (x86)/
,则为 32 位
【讨论】:
您好。我似乎遇到了这个问题。我安装了 32 位 Python,但仍然是同样的问题。问题是否可能是“easy_install mysql-python”命令不知道它应该使用 32 位版本? 我在 64 位 Windows 8.1 上安装了 64 位 Python 3.5.2,安装了 64 位版本的 C/C++ 连接器(适用于 VS 2015),但 MariaDB 版本是 32 位。安装 32 位 Python 3.5.2 和 32 位版本的 C/C++ 连接器后,编译没有任何问题。一切都很好。【参考方案3】:您的安装似乎没有检测到 mysql 客户端库。 从您的 mysql 安装中查找 mysqlcppconn.dll 并将其复制到构建脚本读取的文件夹中,例如 windows 文件夹。欲了解更多信息,请查看此链接https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-apps-windows-visual-studio.html#connector-cpp-application-build-dynamic
【讨论】:
【参考方案4】:我试过这个,它在 Win7 64 位安装 anaconda 时对我有用。 在命令提示符中输入:
pip 安装 mysql-python
我的安装工作正常,因为我使用的是 Studio 2010。
【讨论】:
OP 已经尝试过pip install mysql-python
。您是说解决方案是使用 Studio 2010 吗? ***.com/a/12590280/1766755 提到使用 VS Express 可能是个问题。
是的,不幸的是我建议尝试安装 Studio 2010以上是关于在 Windows 上使用 PIP 编译 mysql-python的主要内容,如果未能解决你的问题,请参考以下文章
使用 python 子进程检查 pip 是不是安装在 Windows 上