Mac OS X 10.6、Mysql、Mysql Python、Django 更新:

Mac OS X 10.6、Mysql、Mysql Python、Django 更新:,mysql,django,macos,architecture,pip,Mysql,Django,Macos,Architecture,Pip,我看到了这篇文章:看到了两种选择: 将MySQL客户端库添加到LD_LIBRARY_路径 mysql_config--libs -L/usr/local/mysql/lib-lmysqlclient-lpthread 所以我不需要在这里做任何事情 只需要升级到Python 2.7,然后重新安装mysqldb 问题: 成功安装django并运行VirtualEnvironment,并使用sqlite3创建项目。我想用mysql来管理数据库 设置.py DATABASES = { 'def

我看到了这篇文章:看到了两种选择:

  • 将MySQL客户端库添加到LD_LIBRARY_路径

    mysql_config--libs -L/usr/local/mysql/lib-lmysqlclient-lpthread

  • 所以我不需要在这里做任何事情

  • 只需要升级到Python 2.7,然后重新安装mysqldb
  • 问题: 成功安装django并运行VirtualEnvironment,并使用sqlite3创建项目。我想用mysql来管理数据库

    设置.py

    DATABASES = {
         'default': {
             'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
             'NAME': 'blog',                      # Or path to database file if using sqlite3.
             'USER': 'root',                      # Not used with sqlite3.
             'PASSWORD': 'root',                  # Not used with sqlite3.
             'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
             'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
         } }
    
    这让我很沮丧:表演之后:

    sudo python manage.py runserver
    
    我得到的错误是:

     Traceback (most recent call last):
      File "manage.py", line 14, in <module>
        execute_manager(settings)
      File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 209, in execute
        translation.activate('en-us')
      File "/Library/Python/2.6/site-packages/django/utils/translation/__init__.py", line 100, in activate
        return _trans.activate(language)
      File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 202, in activate
        _active.value = translation(language)
      File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 185, in translation
        default_translation = _fetch(settings.LANGUAGE_CODE)
      File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
        app = import_module(appname)
      File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
        __import__(name)
      File "/Users/james/Projects/current/code/blog/jamesapps/../jamesapps/tagging/__init__.py", line 3, in <module>
        from tagging.managers import ModelTaggedItemManager, TagDescriptor
      File "/Users/james/Projects/current/code/blog/jamesapps/../jamesapps/apps/tagging/__init__.py", line 3, in <module>
        from tagging.managers import ModelTaggedItemManager, TagDescriptor
      File "/Users/james/Projects/current/code/blog/blog/django-tagging/tagging/managers.py", line 5, in <module>
      File "/Library/Python/2.6/site-packages/django/contrib/contenttypes/models.py", line 1, in <module>
        from django.db import models
      File "/Library/Python/2.6/site-packages/django/db/__init__.py", line 78, in <module>
        connection = connections[DEFAULT_DB_ALIAS]
      File "/Library/Python/2.6/site-packages/django/db/utils.py", line 93, in __getitem__
        backend = load_backend(db['ENGINE'])
      File "/Library/Python/2.6/site-packages/django/db/utils.py", line 33, in load_backend
        return import_module('.base', backend_name)
      File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
        __import__(name)
      File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
        raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
      Referenced from: /Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/_mysql.so
      Reason: image not found
    
    •   Stop the database server
    •   sudo rm /usr/local/mysql
    •   sudo rm -rf /usr/local/mysql*
    •   sudo rm -rf /Library/StartupItems/MySQLCOM
    •   sudo rm -rf /Library/PreferencePanes/My*
    •   edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
    •   rm -rf ~/Library/PreferencePanes/My*
    •   sudo rm -rf /Library/Receipts/mysql*
    •   sudo rm -rf /Library/Receipts/MySQL*
    •   sudo rm -rf /private/var/db/receipts/*mysql*
    
    ~/.bash\u配置文件包含

    export PATH=/usr/local/mysql/bin:$PATH
    export EDITOR="$HOME/bin/mate -w"
    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
    
    如果我这样做了

    python shell
    import MySQLdb
    
    这不显示任何内容

    我已经阅读了以下文章和页面,包括更多内容:

    Mac OS X 10.6.8 2x2Ghz Dual-Core Intel Xeon
    /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
    /usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
    /usr/bin/python (for architecture i386):    Mach-O executable i386
    /usr/bin/python (for architecture ppc7400): Mach-O executable ppc
    
     <https://stackoverflow.com/questions/7335853/mysql-python-installation-problems-on-mac-os-x-lion>
    <https://stackoverflow.com/questions/1299013/problem-using-mysqldb-symbol-not-found-mysql-affected-rows>
    <http://friendlybit.com/tutorial/install-mysql-python-on-mac-os-x-leopard/>
    
    sudo ARCHFLAGS='-arch x86_64' python setup.py build
    sudo ARCHFLAGS='-arch x86_64' python setup.py install
    
    使用pip卸载mysql python,然后从源代码重新编译:

    Mac OS X 10.6.8 2x2Ghz Dual-Core Intel Xeon
    /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
    /usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
    /usr/bin/python (for architecture i386):    Mach-O executable i386
    /usr/bin/python (for architecture ppc7400): Mach-O executable ppc
    
     <https://stackoverflow.com/questions/7335853/mysql-python-installation-problems-on-mac-os-x-lion>
    <https://stackoverflow.com/questions/1299013/problem-using-mysqldb-symbol-not-found-mysql-affected-rows>
    <http://friendlybit.com/tutorial/install-mysql-python-on-mac-os-x-leopard/>
    
    sudo ARCHFLAGS='-arch x86_64' python setup.py build
    sudo ARCHFLAGS='-arch x86_64' python setup.py install
    

    我哪里出了问题,是因为mysql客户端没有正确配置此版本的mysql python吗?

    我通常在Mac上使用自制软件安装mysql(这是一个非常轻松的过程),并且“找不到映像”是我记得在升级mysql版本后没有重新安装mysql python时看到的

    我的建议是卸载MySQL和MySQL python,安装并运行:

    brew install mysql
    pip install MySQL-python
    

    sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib

    谢谢你的回复,但我确实找到了解决问题的方法。理解错误消息后,我只需要创建一个libmysqlclient.18.dylib文件的符号,如下所示:sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib