【问题标题】:Access separate MySQL server from my machine using Python - how? [Mac OS X]使用 Python 从我的机器访问单独的 MySQL 服务器 - 如何? [Mac OS X]
【发布时间】:2014-01-04 04:21:48
【问题描述】:

长话短说 - 我正在编写需要访问外部服务器的 MySQL 数据库的 Selenium webdriver Python 测试。我尝试使用sudo easy_install MYSQL-python 安装mysqldb,但我收到了这条消息:

EnvironmentError: mysql_config not found`(完整(长)追溯如下)。

我对 Python 有点陌生,所以我不完全理解这一点,但这是说我需要在本地机器上安装 MySQL 吗?如果是这样,我将如何做到这一点,因为我不需要它,还有其他方法可以推荐吗?另外,我正在使用Mac OS X Mavericks (10.9) 运行 Mac。

Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 10, in <module>
    load_entry_point('setuptools==0.6c12dev-r88846', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1712, in main
    with_ei_usage(lambda:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1700, in with_ei_usage
    return f()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 1716, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 446, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 476, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 655, in install_eggs
    return self.build_and_install(setup_script, setup_base)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 930, in build_and_install
    self.run_setup(setup_script, setup_base, args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 919, in run_setup
    run_setup(setup_script, args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 62, in run_setup
    lambda: execfile(
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 105, in run
    return func()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 64, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 18, in <module>
File "/tmp/easy_install-Lk4VVX/MySQL-python-1.2.4/setup_posix.py", line 43, in get_config
File "/tmp/easy_install-Lk4VVX/MySQL-python-1.2.4/setup_posix.py", line 25, in mysql_config
EnvironmentError: mysql_config not found

【问题讨论】:

    标签: mysql macos python-2.7 mysql-python


    【解决方案1】:

    您面临的错误消息是由于您的机器上缺少标头。也就是说,您缺少一些库。

    如果您使用的是基于Debian 的Linux 操作系统,我建议您使用通过aptitude 提供的软件包:

    sudo apt-get install python-mysqldb
    

    顺便说一句,放弃轻松安装并开始使用pip

    sudo apt-get install python-pip
    

    如果您只想使用 pip/another Python 依赖管理器安装此模块,您需要在您的机器上安装多个工具/库才能构建它:

    sudo apt-get install python-dev libmysqlclient-dev
    sudo pip install MySQL-python
    

    【讨论】:

    猜你喜欢
    • 2020-07-04
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多