2009-12-14 7 views
9

Il y avait déjà d'excellentes réponses à cette question, mais elles sont maintenant obsolètes.Django + MySQL sous Mac OS 10.6.2 Snow Leopard

Je suis en mesure d'obtenir le module installé, mais "python manage.py runserver" échoue avec

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$ 

De même, à partir du shell 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) 
>>> 

utilisant MySQL-python -1.2.3c1 avec setuptools-0.6c11-py2.6.egg

Toute aide serait appréciée.

+1

Avez-vous mis à jour votre MySQL après l'installation de MySQL-python? –

Répondre

21

J'ai finalement résolu mon propre problème, avec bien sûr, le subconscient et l'aide consciente des nombreux messages, blogs et journaux que j'ai lus. Je donnerais des liens si je pouvais me souvenir.

En un mot, j'ai réinstallé TOUT en utilisant MacPorts. Après avoir édité ~/.bash_profile et commenté toutes les modifications précédentes à $ {PATH}, j'ai téléchargé le dmg for Snow Leopard et j'ai exécuté son installation. Ensuite, a ouvert le terminal et a exécuté la mise à jour automatique.

sudo port selfupdate 
sudo port install python26 

Cette deuxième partie, l'installation de Python 2.6, a pris une éternité. Mais quand il a terminé il m'a incité avec ce qui suit:

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

sudo port install python_select 
sudo python_select python26 

J'ai fait les deux et ils sont allés vite.

J'ai oublié de mentionner à quel point la commande 'port search' est pratique. J'ai cherché 'mysql' et similaire pour trouver la chose à taper après 'installer'. Mais j'ai procédé à la réinstallation du client et du serveur pour MySQL. Peut-être que j'ai fait cela dans l'ordre inverse, mais le résultat final a bien fonctionné.

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. 

Alors, naturellement:

sudo port install mysql5-server 

J'aime la façon dont le tant des installations de MacPorts vous donner des commentaires à ce qu'il faut faire.A la fin de l'installation du serveur, il dit ce qui suit:

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

Il était une nouvelle installation pour me (n'a pas eu de schémas locaux). Pour être complet, et pour ma propre référence, voici la sortie de l'exécution de cette commande:

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/ 

Presque terminé. Plus tôt dans mon « search'ing port je suis tombé sur ce port intéressant:

py26-mysql @ 1.2.2 (python, devel, bases de données) l'interface Python à mysql

Avec beaucoup d'espoir, bien que cela fournissez-moi le paquet MySQLdb, je l'ai installé (et c'est fait).

sudo port install py26-mysql 

Afterwords Je coudés l'interpréteur Python a tenté d'importer MySQLdb, la chose à ma façon tout ce temps.

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 
>>> 

Un avertissement, mais cela a fonctionné !!

Juste une chose:

sudo port install py26-django 

Après tout cela, j'ai enfin pu tourner la manivelle mon projet Django et se connecter à distance au serveur MySQL de mon entreprise !! Il n'a peut-être pas été nécessaire de réinstaller Django en utilisant MacPorts, mais je n'allais pas risquer de complications.

+3

'python_select' semble être désuète. Utilisez 'sudo port select python python26' – hughes

1

Cela se produit lorsque vous avez un logiciel mixte 32 et 64 bits.

Fondamentalement, pour Snow Leopard, vous devez installer le paquet MySQL 64bit (qui est toujours listé comme 10.5, mais ce n'est pas un problème), après cela faire une installation facile de python-mysql à nouveau. Tout va fonctionner.

+0

J'ai installé mysql-5.1.41-osx10.5-x86_64.dmg Depuis le dossier MySQL-python-1.2.3c1 j'ai couru: sudo easy_install. Il a donné plusieurs avertissements comme: fichier n'est pas de l'architecture requise –

4

J'ai écrit un billet de blog il y a quelques mois après mon installation réussie de MySQL sur Snow Leopard:

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

Si vous suivez ces étapes, il devrait (théoriquement) résoudre votre problème (qui ressemble c'est causé par un mélange de logiciels 32 bits et 64 bits). En passant, je n'essaie pas de m'auto-promouvoir ici; le texte dans le billet de blog est fondamentalement ce que j'aurais posté ici, et j'essaye d'appliquer DRY à plus de secteurs de ma vie :)

+0

Votre lien est mort .. – Totic

Questions connexes