I am a newbie learning Python/Django...
我是学Python/Django的新手…
Am using the following tutorial located here.
我正在使用下面的教程。
Created a mysite database in MySQL 5 running on Snow Leopard.
在“雪豹”上创建了一个MySQL 5的mysite数据库。
Edited the settings.py file to look like this:
编辑设置。py文件看起来是这样的:
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'mysite'
DATABASE_USER = 'root'
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''
Now when I run the following command:
现在当我运行以下命令:
python manage.py syncdb
I receive the following error:
我收到以下错误:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/management/__init__.py", line 362,
in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/management/__init__.py", line 303,
in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/management/base.py", line 195, in
run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/management/base.py", line 221, in
execute
self.validate()
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: No module named MySQLdb
What am I possibly doing wrong?
我做错了什么?
Happy programming...
快乐编程…
5 个解决方案
#1
14
sudo easy_install mysql-python
will install the MySQLdb module to allow you to work with MySQL from Python, or, if you want to work with virtualenv (which you should),
将安装MySQLdb模块以允许您使用Python中的MySQL,或者,如果您希望使用virtualenv(您应该使用它),
sudo easy_install virtualenv virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PIP_VIRTUALENV_BASE=$WORKON_HOME
source /usr/local/bin/virtualenvwrapper_bashrc
mkvirtualenv mysite
pip install mysql-python django
Will put you inside a virtualenv with a current install of django (you can specify which version, e.g. django==1.1.1) and the MySQLdb module installed. Using virtualenv will allow you to have separate environments for different projects so you can install different modules and even use different versions of those modules (or Python) for different projects. To leave you virtualenv just type the command
将把您放入一个virtualenv中,并安装django(您可以指定哪个版本,例如django==1.1.1)和安装的MySQLdb模块。使用virtualenv可以为不同的项目提供不同的环境,因此可以安装不同的模块,甚至可以为不同的项目使用不同版本的模块(或Python)。要离开您,virtualenv只需键入命令。
deactivate
or, to switch to the environment 'foo' type
或者,切换到环境“foo”类型。
workon foo
You should also, if you're going to be using virtualenv add these three lines to your ~/.bash_profile (on OS X, ~/.bashrc generally on Linux):
如果您打算使用virtualenv,您也应该将这三行添加到~/中。bash_profile(在OS X上,~/。bashrc通常(在Linux上):
export WORKON_HOME=$HOME/.virtualenvs # where virtualenvs should be created
export PIP_VIRTUALENV_BASE=$WORKON_HOME # tells pip where to look for virtualenvs
source /usr/local/bin/virtualenvwrapper_bashrc # bash completion and wrapper functions for virtualenv
#2
12
The problem is that you are missing the Python module that interfaces with MySQL.
问题是您丢失了与MySQL接口的Python模块。
See the Django docs for get your database running which further points to MySQL notes.
请参阅Django文档,以获得数据库运行,进一步指向MySQL说明。
However, if you are just going through the tutorial it is much easier to use SQLite backend which is built-in to Python. No drivers, server, etc. needed.
但是,如果您正在学习本教程,那么使用Python内置的SQLite后端会容易得多。不需要驱动程序、服务器等。
#3
2
It's worth pointing out (even at this late date) that the "ImproperlyConfigured" error below
值得指出的是(即使是在这个较晚的日期)下面的“非完全配置”错误
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages /django/db/backends/mysql/base.py", line 13, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb文件“/库/框架/ Python.framework /版本/ 2.6 / lib / python2.6 /网站/ django / db /后端/ mysql /基地。在raise中,第13行是完全配置的(“错误加载MySQLdb模块:%s”% e) django.core.exception。错误加载MySQLdb模块:没有名为MySQLdb的模块
can be a red herring in cases where mysql isn't running - I was just googling this error myself, wondering why a misconfiguration had 'suddenly' appeared and while searching and prodding I ran some other manage.py command and got this similar, but much more helpful, error:
在mysql没有运行的情况下,这可能是一个转移注意力的问题——我自己刚刚在谷歌上搜索这个错误,不知道为什么会突然出现一个错误配置,在搜索和推动的过程中,我运行了一些其他的管理。py命令,得到了类似的,但更有用的错误:
File "~/.virtualenvs/mdid3/lib/python2.7/site-packages/MySQLdb/connections.py", line 187, in init
文件”~ / .virtualenvs mdid3 / lib / python2.7 /网站/ MySQLdb /连接。在init中,第187行
super(Connection, self).init(*args, **kwargs2)
超级(连接,自我)。init(* args,* * kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (61)")
_mysql_exceptions。OperationalError:(2003,“127.0.0.1’无法连接到MySQL服务器(61)”)
After checking mysqld, finding it not running and starting it -- my configuration error was miraculously fixed!
在检查mysqld之后,发现它没有运行并启动——我的配置错误奇迹般地得到了修复!
#4
1
Try this if you are using
如果你正在使用这个
linux:- sudo apt-get install python-mysqldb
- sudo apt-get install python-mysqldb
windows:- pip install python-mysqldb
or easy_install python-mysqldb
windows:- pip安装python-mysqldb或easy_install python-mysqldb。
Hope this should work
希望这应该的工作
#5
0
Make sure to create your database and with your MySQL server running try to connect to the database to check that database name, username and password are correct. then run:
确保创建数据库,并使用MySQL服务器运行尝试连接数据库,以检查数据库名、用户名和密码是否正确。然后运行:
1) pip install mysqlclient
1)pip安装mysqlclient
2) python manage.py migrate
2)python管理。py迁移
#1
14
sudo easy_install mysql-python
will install the MySQLdb module to allow you to work with MySQL from Python, or, if you want to work with virtualenv (which you should),
将安装MySQLdb模块以允许您使用Python中的MySQL,或者,如果您希望使用virtualenv(您应该使用它),
sudo easy_install virtualenv virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PIP_VIRTUALENV_BASE=$WORKON_HOME
source /usr/local/bin/virtualenvwrapper_bashrc
mkvirtualenv mysite
pip install mysql-python django
Will put you inside a virtualenv with a current install of django (you can specify which version, e.g. django==1.1.1) and the MySQLdb module installed. Using virtualenv will allow you to have separate environments for different projects so you can install different modules and even use different versions of those modules (or Python) for different projects. To leave you virtualenv just type the command
将把您放入一个virtualenv中,并安装django(您可以指定哪个版本,例如django==1.1.1)和安装的MySQLdb模块。使用virtualenv可以为不同的项目提供不同的环境,因此可以安装不同的模块,甚至可以为不同的项目使用不同版本的模块(或Python)。要离开您,virtualenv只需键入命令。
deactivate
or, to switch to the environment 'foo' type
或者,切换到环境“foo”类型。
workon foo
You should also, if you're going to be using virtualenv add these three lines to your ~/.bash_profile (on OS X, ~/.bashrc generally on Linux):
如果您打算使用virtualenv,您也应该将这三行添加到~/中。bash_profile(在OS X上,~/。bashrc通常(在Linux上):
export WORKON_HOME=$HOME/.virtualenvs # where virtualenvs should be created
export PIP_VIRTUALENV_BASE=$WORKON_HOME # tells pip where to look for virtualenvs
source /usr/local/bin/virtualenvwrapper_bashrc # bash completion and wrapper functions for virtualenv
#2
12
The problem is that you are missing the Python module that interfaces with MySQL.
问题是您丢失了与MySQL接口的Python模块。
See the Django docs for get your database running which further points to MySQL notes.
请参阅Django文档,以获得数据库运行,进一步指向MySQL说明。
However, if you are just going through the tutorial it is much easier to use SQLite backend which is built-in to Python. No drivers, server, etc. needed.
但是,如果您正在学习本教程,那么使用Python内置的SQLite后端会容易得多。不需要驱动程序、服务器等。
#3
2
It's worth pointing out (even at this late date) that the "ImproperlyConfigured" error below
值得指出的是(即使是在这个较晚的日期)下面的“非完全配置”错误
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages /django/db/backends/mysql/base.py", line 13, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb文件“/库/框架/ Python.framework /版本/ 2.6 / lib / python2.6 /网站/ django / db /后端/ mysql /基地。在raise中,第13行是完全配置的(“错误加载MySQLdb模块:%s”% e) django.core.exception。错误加载MySQLdb模块:没有名为MySQLdb的模块
can be a red herring in cases where mysql isn't running - I was just googling this error myself, wondering why a misconfiguration had 'suddenly' appeared and while searching and prodding I ran some other manage.py command and got this similar, but much more helpful, error:
在mysql没有运行的情况下,这可能是一个转移注意力的问题——我自己刚刚在谷歌上搜索这个错误,不知道为什么会突然出现一个错误配置,在搜索和推动的过程中,我运行了一些其他的管理。py命令,得到了类似的,但更有用的错误:
File "~/.virtualenvs/mdid3/lib/python2.7/site-packages/MySQLdb/connections.py", line 187, in init
文件”~ / .virtualenvs mdid3 / lib / python2.7 /网站/ MySQLdb /连接。在init中,第187行
super(Connection, self).init(*args, **kwargs2)
超级(连接,自我)。init(* args,* * kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (61)")
_mysql_exceptions。OperationalError:(2003,“127.0.0.1’无法连接到MySQL服务器(61)”)
After checking mysqld, finding it not running and starting it -- my configuration error was miraculously fixed!
在检查mysqld之后,发现它没有运行并启动——我的配置错误奇迹般地得到了修复!
#4
1
Try this if you are using
如果你正在使用这个
linux:- sudo apt-get install python-mysqldb
- sudo apt-get install python-mysqldb
windows:- pip install python-mysqldb
or easy_install python-mysqldb
windows:- pip安装python-mysqldb或easy_install python-mysqldb。
Hope this should work
希望这应该的工作
#5
0
Make sure to create your database and with your MySQL server running try to connect to the database to check that database name, username and password are correct. then run:
确保创建数据库,并使用MySQL服务器运行尝试连接数据库,以检查数据库名、用户名和密码是否正确。然后运行:
1) pip install mysqlclient
1)pip安装mysqlclient
2) python manage.py migrate
2)python管理。py迁移