线程中未处理的异常启动python manage.py runserver [英] Unhandled exception in thread started python manage.py runserver

查看:371
本文介绍了线程中未处理的异常启动python manage.py runserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在我的环境(Windows 8.1)中安装了Python 3.4.3,并尝试部署一个简单的Django服务器。当我运行命令 python manage.py runserver ,但出现以下异常:


线程中未处理的异常,由.wrapper在0x031B5D68开始>


我相信这个异常是由于某些错误或误解,当我尝试安装的MySQL-蟒。我将 settings.py 中的 DATABASE 配置从django.db.backends.mysql更改为django.db .backends.sqlite3并且运行良好。我尝试的配置如下:

 #配置有缺陷
DATABASES = {
'default' :{
'ENGINE':'django.db.backends.mysql',
'NAME':'test',
'USER':'user',
'PASSWORD ':'doideira',
'HOST':'127.0.0.1',
'PORT':'3306',
}
}

但使用SQLite的作品:

  #with SQLite 3 works 
DATABASES = {
'default':{
'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path .join(BASE_DIR,'db.sqlite3'),
}
}

我正在经历一些麻烦,任何建议将不胜感激。我想知道为什么会发生这种情况,如何解决这个问题。



更多信息:




  • Mysql版本是5.6.4

  • Mysql Python版本是1.2.5

  • Python版本是1.2.5

  • Windows 8.1

  • Django版本是1.8.1



here 可以看到完整的日志错误。



更新 2015年5月16日,星期六



我想出了一个简单的解决方案:将Python从3.x降级到2.7.x。我将我的问题的答案解释下面的步骤。我还发现这个答案非常有用,但现在我使用的是Python 2.7,一切都OK。



我还发现这篇文章回答了我应该用Python 2或Python 3为我的开发活动,这是什么让我决定是否保持Python3或Python2。由于Python3没有强大的库支持,所以我会稍等一下,直到更新它。

解决方案

Eureka!我想出了答案。



作为评论中提到的@nikhiln,Python 3.x不支持mysql-python:


MySQL-3.23至5.5和Python-2.4至2.7目前支持。将来的版本中将支持Python-3.0。支持PyPy。
mysql-python 1.2.5


为了解决这个问题,我将Python从3.4降级到了2.7.9,并安装了 Microsoft Visual C ++ Compiler for Python 2.7 Microsoft Visual C ++ 2008 SP1可再发行组件包(x64)正确运行。



然后,我使用 .whl 文件安装了mysql-python客户端rel =nofollow> Christoph Gohlke的Python扩展软件包的非官方Windows二进制文件。我做了如下(假设C ++ 2008,Python的编译器和 Pip 已经安装):


  1. pip install wheel 安装滚轮程序。使用它,您可以编译 .whl 文件。

  2. 下载正确的文件MySQL_python-1.2.5-cp27-none -...

  3. 运行命令 pip install MySQL_python-1.2.5-cp27-none -... whl (该文件你

And Voilà! mysql-python现在运行很快!
要检查一切是否正常,只需运行将MySQLdb 导入Python shell。

 >>>导入MySQLdb 

如果没有提出异常,那么工作就完成了。


Recently I installed Python 3.4.3 in my environment (Windows 8.1) and tried to deploy a simple Django server. When I runned the command python manage.py runserver but the following exceptions appeared:

Unhandled exception in thread started by .wrapper at 0x031B5D68>

I believe this exception happened due some error or misconception when I tried to install mysql-python. I changed the DATABASE config in settings.py from "django.db.backends.mysql" to "django.db.backends.sqlite3" and runned pretty well. The configs that I tried are the following:

# Defective configuration
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'test',
    'USER': 'user',
    'PASSWORD': 'doideira',
    'HOST': '127.0.0.1',
    'PORT': '3306',
  } 
}

But using SQLite works:

# With SQLite 3 works
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.sqlite3',
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  }
}

I am experiencing some troubles and any advice would be appreciated. I would like to know why this is happening and how can I workaround it.

Further info:

  • Mysql version is 5.6.4
  • Mysql Python version is 1.2.5
  • Python version is 1.2.5
  • Windows 8.1
  • Django version is 1.8.1

The full log error can be seen here.

Update Saturday 16, May 2015:

I came up with an simple solution: downgrade Python from 3.x to 2.7.x. I explain the steps below as the answer of my question. I also found this answer very useful, but now that I'm using Python 2.7 everything is ok.

I also found this article that answers the question "Should I use Python 2 or Python 3 for my development activity" and that was what made me to decide whether keep with Python3 or Python2. Since Python3 hasn't a strong library support, I will wait a little more until update it.

解决方案

Eureka! I figured out the answer guys.

As @nikhiln mentioned in the comments, mysql-python is not supported yet for Python 3.x:

MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported. mysql-python 1.2.5

To work around it, I downgraded my Python from 3.4 to 2.7.9, and installed the Microsoft Visual C++ Compiler for Python 2.7 and Microsoft Visual C++ 2008 SP1 Redistributable Package (x64) to properly run it.

Then I installed the mysql-python client using a .whl file from Christoph Gohlke`s Unofficial Windows Binaries for Python Extension Packages. I did as following (assuming C++ 2008, Compiler for Python and Pip are already installed):

  1. pip install wheel to install the wheel program. With it you are able to compile .whl files.
  2. Download the properly file MySQL_python‑1.2.5‑cp27‑none‑...
  3. Run the command pip install MySQL_python‑1.2.5‑cp27‑none‑...whl (the file you downloaded in the previous step).

And Voilà! mysql-python is running swiftly now! To check if everything is ok, just run import MySQLdb into Python shell.

>>> import MySQLdb

If no exception was raised, then the work is done.

这篇关于线程中未处理的异常启动python manage.py runserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆