在Amazon EC2上使用Django syncdb时出现问题
我正在尝试在我的EC2实例上部署我的项目。
当我运行 python manage.py validate
时,出现了这个错误 Error: No module named mysql.base
。
我已经通过 yum install MySQL-python
安装了MySQL-python。并且我可以在Python解释器中成功导入MySQLdb。
我似乎搞不清楚问题出在哪里?
我使用的是Django 1.3、Python 2.6和MySQLdb 1.2.3c1。
更新
好的,我在这个目录 /usr/lib**64**/python2.6/site-packages/
找到了MySQL-python文件,而不是在 /usr/lib/python2.6/site-packages/
。所以现在我尝试通过 wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
手动下载MySQL-python文件,位置是在我的 /usr/lib/python2.6/site-packages/
目录下,现在我在运行 python setup.py build
时遇到了这个错误。
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.6
creating build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.6/MySQLdb
creating build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
操作系统详情
Amazon Linux AMI Base 2011.02.1, EBS boot, 64-bit architecture with Amazon EC2 AMI Tools
The Amazon Linux AMI is based on RHEL 5.x and parts of RHEL6
更新
我在一个32位的实例上重新做了这个项目,现在可以正常工作。
3 个回答
打开你的 settings.py
文件。如果你把 ENGINE
改成 mySQL
,你应该这样修改:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2',
'mysql', 'sqlite3' or 'oracle'.
...
}
试试这个
pip install mysql-python
或者
easy_install mysql-python
或者下载这个包,然后用 python 脚本 setup.py 来安装
编辑:
试着在 python 终端里进行导入
from mysql.base import *
或者直接启动
python manage.py shell
如果你能这样做,可能在 /home/djangotest/sgelections/apache/django.wsgi 这个文件里有问题
一个极端的例子(哈哈):
import sys
sys.path = []
你在用什么操作系统?
你是默认安装了Python 2.6,还是自己手动安装的?
我问这个是因为,当你用yum install命令时,它会根据你操作系统上安装的Python版本来安装mysql-python客户端。比如在CentOS 5.5上,默认是Python 2.4.x。
如果你是通过Python的alt-install选项手动安装了Python 2.6,那么mysql-python很可能是为你机器上默认的Python版本安装的,而不是Python 2.6。
你可以去/usr/lib/python2.6/site-packages这个文件夹看看,里面有没有MySQL_python。如果没有的话,你就需要用easy_install或者pip再安装一次,或者自己下载mysql-python包然后手动安装。或者你也可以把现在安装的路径加到你的Python路径里。
如果你在机器上搜索MySQL_python,你可以找到它现在安装在哪里,这样能帮助你更好地理解发生了什么。