python - Mac OS 10.6.2 Snow Leopard 上的 Django + MySQL

标签 python mysql django osx-snow-leopard

这个问题已经有一些很好的答案,但是,它们现在已经过时了。

我已经能够安装模块,但是“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$ 

同样,来自 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)
>>> 

使用 MySQL-python-1.2.3c1 和 setuptools-0.6c11-py2.6.egg

如有任何帮助,我们将不胜感激。

最佳答案

我最终解决了自己的问题,当然,我阅读的许多帖子、博客和邮件日志都提供了潜意识和有意识的帮助。如果我记得的话,我会提供链接。

简而言之,我使用 MacPorts 重新安装了所有东西。

编辑 ~/.bash_profile 并注释掉之前对 ${PATH} 的所有修改后,我下载了 dmg for Snow Leopard并运行了它的安装。

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

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”和类似的东西,以找到要在“安装”之后键入的内容。但是我继续为 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/

快完成了。在我之前的“端口搜索”中,我遇到了这个有趣的端口:

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

非常非常希望这会为我提供 MySQLdb 包,我安装了它(并且确实如此)。

sudo port install py26-mysql

之后我启动了 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
>>> 

一个警告,但它起作用了!

还有一件事:

sudo port install py26-django

完成所有这些之后,我终于能够启动我的 Django 项目并远程连接到我公司的 MySQL 服务器!可能没有必要使用 MacPorts 重新安装 Django,但我不想冒并发症的风险。

关于python - Mac OS 10.6.2 Snow Leopard 上的 Django + MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1904039/

相关文章:

python - pyspark解析固定宽度的文本文件

python - 如何将 django 模型方法转换为参数?

php - Zend 多个 where

django - 通过Django create方法传递save参数

javascript - 如何在javascript中选择分配给Django变量的html id

django - 带有身份验证但没有 ssh 的 Git

python - 优化算法以处理元组、集合和字典

Python 使用 xarray 从 NETCDF 文件中提取多个纬度/经度

mysql - 如何在mysql数据库中存储日期?

mysql - 单击按钮时从多个表单插入数据