python Mac OS 10.6.2 Snow Leopard 上的 Django + MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1904039/
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
Django + MySQL on Mac OS 10.6.2 Snow Leopard
提问by Daniel Rhoden
There were some excellent answers to this question already, however, they are now outdated.
这个问题已经有一些很好的答案,但是,它们现在已经过时了。
I've been able to get the module installed, but "python manage.py runserver" fails with
我已经能够安装模块,但是“python 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$
Likewise, from the python shell:
同样,从 python shell:
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)
>>>
Using MySQL-python-1.2.3c1 with setuptools-0.6c11-py2.6.egg
使用 MySQL-python-1.2.3c1 和 setuptools-0.6c11-py2.6.egg
Any help would be appreciated.
任何帮助,将不胜感激。
回答by Daniel Rhoden
I have ultimately solved my own problem, with of course, the subconscious and conscious help from the many posts, blogs, and mail logs I've read. I would give links if I could remember.
我最终解决了我自己的问题,当然,在我读过的许多帖子、博客和邮件日志的潜意识和有意识的帮助下。如果我记得的话,我会给链接。
In a nutshell, I reinstalled EVERYTHING using MacPorts.
简而言之,我使用 MacPorts 重新安装了所有东西。
After editing ~/.bash_profile and commenting out all the previous modifications to ${PATH}, I downloaded the dmg for Snow Leopardand ran through its installation.
在编辑 ~/.bash_profile 并注释掉之前对 ${PATH} 的所有修改后,我下载了Snow Leopard的dmg并运行了它的安装。
Then opened the terminal and ran the self update.
然后打开终端并运行自我更新。
sudo port selfupdate
sudo port install python26
That second part, installing Python 2.6, took forever. But when it completed it prompted me with the following:
第二部分,安装 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
I did both and they went quick.
我做了两个,他们很快。
I forgot to mention how handy 'port search ' command is. I searched for 'mysql' and similar to find the thing to type after 'install'. But I proceeded with reinstalling both the client and server for MySQL. Perhaps I did this in reverse order, but the end result worked fine.
我忘了提及“端口搜索”命令是多么方便。我搜索了“mysql”并类似地找到了“安装”后要键入的内容。但我继续为 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.
So naturally:
所以很自然:
sudo port install mysql5-server
I love how the so many of the macports installations give you feedback as to what to do next. At the end of the server installation, it said the following:
我喜欢如此多的 macports 安装如何为您提供有关下一步做什么的反馈。在服务器安装结束时,它说如下:
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
It was a new install for me (didn't have any local schemas). For completeness, and for my own reference, here is the output of running that command:
这对我来说是一个新安装(没有任何本地架构)。为了完整性和我自己的参考,以下是运行该命令的输出:
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/
Almost done. Earlier in my 'port search'ing I came across this interesting port:
快完成了。早些时候在我的“端口搜索”中,我遇到了这个有趣的端口:
py26-mysql @1.2.2 (python, devel, databases) Python interface to mysql
py26-mysql @1.2.2 (python, devel, databases) mysql 的 Python 接口
With much, much hope that this would provide me with MySQLdb package, I installed it (and it did).
非常非常希望这将为我提供 MySQLdb 包,我安装了它(并且确实如此)。
sudo port install py26-mysql
Afterwords I cranked up the python interpreter attempted to import MySQLdb, the very thing in my way all this time.
之后我启动了 python 解释器试图导入 MySQLdb,这一直是我的方式。
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
>>>
A warning, but It worked!!
一个警告,但它奏效了!!
Just one more thing:
还有一件事:
sudo port install py26-django
After all of this I was finally able to crank up my Django project and remotely connect to my company's MySQL server!! It may not have been necessary to reinstall Django using MacPorts, but I wasn't going to risk complications.
在这一切之后,我终于能够启动我的 Django 项目并远程连接到我公司的 MySQL 服务器!!可能没有必要使用 MacPorts 重新安装 Django,但我不打算冒并发症的风险。
回答by jakeboxer
I wrote a blog post a few months ago following my successful installation of MySQL on Snow Leopard:
几个月前,我在 Snow Leopard 上成功安装 MySQL 后写了一篇博文:
http://jboxer.com/2009/09/installing-mysql-on-snow-leopard/
http://jboxer.com/2009/09/installing-mysql-on-snow-leopard/
If you follow those steps, it should (theoretically) fix your problem (which sounds like it's caused by a mix of 32-bit and 64-bit software).
如果您按照这些步骤操作,它应该(理论上)可以解决您的问题(这听起来像是由 32 位和 64 位软件混合引起的)。
By the way, I'm not trying to self-promote here; the text in the blog post is basically what I would've posted here, and I'm trying to apply DRY to more areas of my life :)
顺便说一句,我不是想在这里自我推销。博客文章中的文字基本上就是我会在这里发布的内容,我正在尝试将 DRY 应用到我生活的更多领域:)
回答by kibitzer
This happens when you have mixed 32 and 64bit software.
当您混合使用 32 位和 64 位软件时会发生这种情况。
Basically, for Snow Leopard, you need to install MySQL 64bit package (which still is listed as 10.5, but that is no problem) , after that do an easy install of python-mysql again. All will work.
基本上,对于Snow Leopard,您需要安装MySQL 64bit 包(仍列为10.5,但没问题),然后再次轻松安装python-mysql。一切都会奏效。