设置mysql数据库时,“ImportError:...预期在:flat namespace”

时间:2012-05-28 00:29:19

标签: django terminal python-2.7 mysql-python enthought

mySQL似乎已经运行得很好。但是当我尝试将MySQLdb导入python时,我得到一个ImportError: ... Expected in: flat namespace。我认为这与python的两个不同版本(两个不同的目录,相同的版本)

有关

操作系统:Mac 10.6.8

$ ls /Library/Frameworks/Python.framework/Versions/
7.2 Current

$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

$ easy_install MySQL-python
...
...
Using /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg
...

$ mysql.server start
Starting MySQL
.. SUCCESS!

$ python manage.py runserver
...
...
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so

$ python
Enthought Python Distribution (EPD) free version -- www.enthought.com
Version: 7.2-2 (32-bit)

>>> import MySQLdb
...
...
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-i386.egg/_mysql.so

所以除了对django和python不熟悉之外,我对使用终端也很陌生,而且我并不确定我在看什么。

但我能说清楚:

  • 我有两个版本,7.2和当前。
  • 如果我打电话给python,它会调用' Current'版。这是有道理的,它在$ PATH。
  • 然而,版本2.7(不是7.2)也在PATH中,我在安装EDP软件包时删除了它。 ......我不完全明白PATH是什么或做什么所以我不想开始改变事情
  • MySQL-python安装在7.2版本中
  • 无法运行服务器,因为flat namespace中的必要文​​件不在{{1}},而且它也安装在
  • 的位置

有没有办法解开这些路径(如果那就是问题)

提前谢谢

1 个答案:

答案 0 :(得分:0)

嗯......我认为它与python的“当前”和“7.2”版本没有任何关系。

在做完

之后似乎已经修好了
pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python

我不确定--universal是否产生差异或使用pip install而不是easy_install