【问题标题】:Problem with Django syncdb on Amazon EC2Amazon EC2 上的 Django syncdb 问题
【发布时间】:2011-07-27 10:55:58
【问题描述】:

我正在尝试在我的 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 @987654321@ 手动下载 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 位实例上重新做了这个项目,它可以工作。

【问题讨论】:

    标签: python mysql django amazon-ec2 mysql-python


    【解决方案1】:

    打开您的settings.py 文件。如果你把ENGINE 变成mySQL,你应该像这样改变它:

    DATABASES = {
      'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 
          'mysql', 'sqlite3' or 'oracle'.
      ...
         }
    

    【讨论】:

      【解决方案2】:

      试试

      pip install mysql-python
      

      easy_install mysql-python
      

      或下载包,然后使用 python 脚本 setup.py 安装

      编辑:

      尝试在 python shell 上进行导入

      from mysql.base import *
      

      或者只是启动

      python manage.py shell
      

      如果您能够这样做,则 /home/djangotest/sgelections/apache/django.wsgi 可能有问题

      一个极端的例子(笑):

      import sys
      sys.path = []
      

      【讨论】:

      • 我尝试了easy_install并手动下载了包,但还是不行。
      • 我试过from mysql.base import *python manage.py shell。他们都导致了同样的错误。
      【解决方案3】:

      您使用的是什么操作系统? 默认情况下是否安装了 python 2.6 是您自己安装的吗?

      我问的原因是因为当您使用 yum install 时,它将为您的操作系统上安装的 python 版本安装 mysql-python 客户端,对于 CentOS 5.5,它是 python2.4.x。

      如果您使用python的alt-install选项手动安装了python2.6,那么mysql-python最有可能安装在您机器上的默认python版本而不是python2.6上。

      如果你进入 /usr/lib/python2.6/site-packages 你会看到 MySQL_python 吗?如果没有,那么您将需要使用 easy_install 或 pip 再次安装它,或者自己下载 mysql-python 包然后手动安装它。或者您可以将现在安装的位置添加到您的 python 路径中。

      如果你在你的机器上搜索 MySQL_python,你可以看到它现在安装在哪里,这应该让你更好地了解发生了什么。

      【讨论】:

      • Python2.6 随我的 ec2 实例一起提供。我试过easy_install,但还是不行。
      • 您使用的是什么 Linux 发行版和版本?您是否查看了站点包以查看是否存在 mysql-python?
      • 我已更新问题以反映解决问题的进度
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多