2009-12-14 126 views
9

这个问题已经有一些很好的答案,但是现在已经过时了。Mac OS 10.6.2上的Django + MySQL Snow Leopard

我已经能够得到安装的模块,但 “蟒蛇manage.py runserver命令” 失败,

iMac:myproject drhoden$ python manage.py runserver 
Validating models... 
Unhandled exception in thread started by <function inner_run at 0x10496f0> 
Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run 
    self.validate(display_num_errors=True) 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate 
    num_errors = get_validation_errors(s, app) 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py", line 22, in get_validation_errors 
    from django.db import models, connection 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 41, in <module> 
    backend = load_backend(settings.DATABASE_ENGINE) 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 17, in load_backend 
    return import_module('.base', 'django.db.backends.%s' % backend_name) 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 13, in <module> 
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) 
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql) 

^CiMac:segisys drhoden$ 

同样,从Python外壳:

iMac:myproject drhoden$ python 
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import MySQLdb 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "build/bdist.macosx-10.3-fat/egg/MySQLdb/__init__.py", line 19, in <module> 

    File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 7, in <module> 
    File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 6, in __bootstrap__ 
ImportError: dynamic module does not define init function (init_mysql) 
>>> 

使用MySQL的Python -1.2.3c1与setuptools-0.6c11-py2.6.egg

任何帮助,将不胜感激。

+1

您是否在安装MySQL-python之后升级您的MySQL? – 2009-12-14 22:45:58

回答

21

我最终解决了我自己的问题,当然,潜意识并从我阅读的许多帖子,博客和邮件日志中获得有意识的帮助。如果我能记得,我会给链接。

简而言之,我使用MacPorts重新安装了一切。

编辑〜/ .bash_profile并注释掉所有先前对$ {PATH}所作的修改后,我下载了dmg for Snow Leopard并完成了它的安装。

然后打开终端并运行自我更新。

sudo port selfupdate 
sudo port install python26 

第二部分,安装Python 2.6,花了很长时间。但是当它完成时,它促使我与以下几点:

To fully complete your installation and make python 2.6 the default, please run 

sudo port install python_select 
sudo python_select python26 

我做了两个,他们走得很快。

我忘了提及如何方便的'端口搜索'命令。我搜索'mysql'和类似的找到'install'后键入的东西。但我继续重新安装MySQL的客户端和服务器。也许我以相反的顺序做了这个,但最终的结果运行良好。

sudo port install mysql5 
... 
---> Installing mysql5 @5.1.41_0 
The MySQL client has been installed. 
If you also want a MySQL server, install the mysql5-server port. 

所以很自然:

sudo port install mysql5-server 

我爱怎么这么多的MacPorts安装的给你反馈,下一步该怎么做。在服务器安装结束时,它表示以下内容:

****************************************************** 
* In order to setup the database, you might want to run 
* sudo -u _mysql mysql_install_db5 
* if this is a new install 
****************************************************** 

这是我的新安装(没有任何本地模式)。为了完整性和我自己的参考,下面是运行该命令的输出:

Installing MySQL system tables... 
OK 
Filling help tables... 
OK 

To start mysqld at boot time you have to copy 
support-files/mysql.server to the right place for your system 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 
To do so, start the server, then issue the following commands: 

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password' 
/opt/local/lib/mysql5/bin/mysqladmin -u root -h iMac.local password 'new-password' 

Alternatively you can run: 
/opt/local/lib/mysql5/bin/mysql_secure_installation 

which will also give you the option of removing the test 
databases and anonymous user created by default. This is 
strongly recommended for production servers. 

See the manual for more instructions. 

You can start the MySQL daemon with: 
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe & 

You can test the MySQL daemon with mysql-test-run.pl 
cd /opt/local/mysql-test ; perl mysql-test-run.pl 

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script! 

The latest information about MySQL is available at http://www.mysql.com/ 
Support MySQL by buying support/licenses from http://shop.mysql.com/ 

几乎完成。在我的“口search'ing早些时候我碰到这个有趣的端口传来:

py26-mysql的@ 1.2.2(蟒蛇,devel的数据库) Python接口到mysql

有了很多很多的希望,这将为我提供MySQLdb包,我安装了它(和它)。

sudo port install py26-mysql 

Afterwords我发动python解释器试图导入My​​SQLdb,这是我一直以来的方式。

iMac:~ drhoden$ python 
Python 2.6.4 (r264:75706, Dec 15 2009, 18:00:14) 
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import MySQLdb 
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet 
>>> 

一个警告,但它的工作!

还有一件事:

sudo port install py26-django 

这一切后,我终于能杀青我的Django项目和远程连接到我公司的MySQL服务器!可能没有必要使用MacPorts重新安装Django,但我不会冒险并发症。

+3

'python_select'似乎已过时。使用'sudo port select python python26' – hughes 2011-08-26 15:29:33

1

当您混合使用32位和64位软件时会发生这种情况。

基本上,对于Snow Leopard,您需要安装MySQL 64位软件包(仍然列为10.5,但这没有问题),然后再次轻松安装python-mysql。一切都会奏效。

+0

我安装了mysql-5.1.41-osx10.5-x86_64.dmg 从MySQL-python-1.2.3c1文件夹中运行: sudo easy_install。 它给出了几个警告,如: 文件不是必需的架构 – 2009-12-15 18:25:17

4

我写了一篇博客文章,几个月前跟着我在Snow Leopard上成功安装的MySQL:

http://jboxer.com/2009/09/installing-mysql-on-snow-leopard/

如果遵循这些步骤,就应该(理论上)解决您的问题(这听起来像它是由32位和64位软件混合引起的)。

顺便说一句,我不是想在这里自我推销;在博客文章中的文本基本上是我会在这里发布的,我试图将DRY应用到我生活中更多的领域:)

+0

您的链接已死亡。 – Totic 2011-06-14 20:14:06

相关问题