在 Mac 上安装 MySQL-python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17599830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:38:19  来源:igfitidea点击:

Installing MySQL-python on mac

pythonmacospython-2.7mysql-python

提问by Ashish Agarwal

I am using OSX 10.8 and PyCharm to work on a Python development project. I have installed MySQL-python for the mac using the instructions on the website

我正在使用 OSX 10.8 和 PyCharm 来处理 Python 开发项目。我已经使用网站上的说明为 mac 安装了 MySQL-python

http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found

http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found

However, running the project gives me this error:

但是,运行该项目给了我这个错误:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so
  Expected in: flat namespace
 in /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so

The file mentioned int the error exists at the location - /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so

该文件提到的错误存在于该位置 - /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so

The entire error message is -

整个错误信息是 -

/usr/local/bin/python2.7-32 /Users/ashishagarwal/Optimus/MashPotato/backend/mashpotato/manage.py testserver --addrport 8000
Running on development server
Traceback (most recent call last):
  File "/Users/ashishagarwal/Optimus/MashPotato/backend/mashpotato/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/management/commands/__init__.py", line 10, in <module>
    import django.template.loaders.app_directories
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loaders/app_directories.py", line 23, in <module>
    mod = import_module(app)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 3, in <module>
    from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/helpers.py", line 4, in <module>
    from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/util.py", line 6, in <module>
    from django.db import models
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so
  Expected in: flat namespace
 in /Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so

Process finished with exit code 1

回答by kissgyorgy

You should install MySQL through Homebrewfirst, to get python-mysql work properly on OS X.

你应该先通过Homebrew安装 MySQL ,让 python-mysql 在 OS X 上正常工作。

pip uninstall MySQL-python
brew install mysql
pip install MySQL-python

回答by garbanzio

Make sure you have the most recent version of Xcode including Command Line Tools. I simply downloaded the 2GB update from the app store. I had a similar problem, specifically this, and that fixed it.

确保您拥有最新版本的 Xcode,包括命令行工具。我只是从应用商店下载了 2GB 更新。我有一个类似的问题,特别是this,并且修复了它。

Cheers!

干杯!

回答by Paul

if you use python like:

如果你使用 python 像:

import mysql.connector

you have to download mysql Connector first here is the link link

你必须先下载mysql连接器这里是链接链接

回答by Gesias

I installed mysql a long time ago with homebrew so when I ran into trouble now after upgrading OSX I reinstalled it again with brew reinstall [email protected](I ran 5.7.10) and reinstalled MySQL-python I expected it to be resolved. Got the error mentioned above.

我很久以前用自制软件安装了 mysql,所以当我在升级 OSX 后遇到麻烦时,我再次重新安装了它brew reinstall [email protected](我运行了 5.7.10)并重新安装了 MySQL-python 我希望它能够得到解决。得到上面提到的错误。

It really did my head in and after spending several hours on it I had no idea what to do, rebuilt from source and everything. Tried other python apps for mysql but it was the same thing.

它真的让我头疼,在花了几个小时之后,我不知道该怎么做,从源代码和一切重建。为 mysql 尝试了其他 python 应用程序,但结果是一样的。

I somehow realised that the client being built by MySQL-python was against the wrong version so I checked where the /usr/local/opt/mysqlwas linked to and there it was, it was linked to a previous version which I had installed via dmg like 7 years ago! Once I removed that link and then ran brew link mysqland then created a new virtualenv and installed all the packages from scratch it finally worked!

我以某种方式意识到由 MySQL-python 构建的客户端针对错误的版本,所以我检查了/usr/local/opt/mysql链接到的位置,它链接到了我 7 年前通过 dmg 安装的以前的版本!一旦我删除了该链接,然后运行brew link mysql,然后创建了一个新的 virtualenv 并从头开始安装了所有软件包,它终于可以工作了!