2015-04-04 70 views
2

我已经在CentOS 7.0版本上安装了Django。Django CentOS 7 - 无法导入姓名Col

#yum install python-pip 
#pip install django 
#cd /home 
#django-admin startproject mysite 
#cd mysite 
#python manage.py runserver 0.0.0.0:8000 

,当我去http://domain.com:8000在网络浏览器,我看到下面的错误。

ImportError at/
cannot import name Col 
Request Method: GET 
Request URL: http://domain.com:8000/ 
Django Version: 1.6.10 
Exception Type: ImportError 
Exception Value:  
cannot import name Col 
Exception Location: /usr/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py in <module>, line 13 
Python Executable: /usr/bin/python 
Python Version: 2.7.5 

应该在CentOS 6.3的工作,但我认为这是在CentOS 7.0

我看着fields.py文件

不同============== ==============================

from __future__ import unicode_literals 

from collections import defaultdict 

from django.core import checks 
from django.core.exceptions import ObjectDoesNotExist 
from django.db import connection 
from django.db import models, router, transaction, DEFAULT_DB_ALIAS 
from django.db.models import signals, FieldDoesNotExist, DO_NOTHING 
from django.db.models.base import ModelBase 
from django.db.models.fields.related import ForeignObject, ForeignObjectRel 
from django.db.models.related import PathInfo 
from django.db.models.sql.datastructures import Col 
from django.contrib.contenttypes.models import ContentType 
from django.utils import six 
from django.utils.deprecation import RenameMethodsBase, RemovedInDjango18Warning 

从django.utils.encoding进口smart_text,python_2_unicode_compatible

就是这样。

+0

请将您的Django码。尤其是导入“Col”的部分。 – 2015-04-04 03:19:29

+0

@KlausD。我更新了Django代码。 – Jake 2015-04-04 11:30:34

回答

2

我在使用Django的时候遇到了同样的问题,结果发现fields.py是从Django(1.7.x)的新版本中剩下的,我可能已经(可能是不正确的)降级了。我卸载了Django,删除了站点包下的剩余Django目录,然后重新安装它,并解决了问题。

+0

我用Django 1.8 @jmriebold非常感谢! – Jake 2015-04-16 16:12:34

0

为了其他人的利益,这里是我的建议 - 回购通常安装可用包。重新安装将再次重新安装相同的错误包。对于基于Python项目使用的代码

sudo pip install Django==1.8.1的#Version

(确保蟒蛇-PIP使用命令之前安装)

,而不是sudo yum -y install python-django#在RHEL,Fedora的