Skip to main content
 首页 » 编程设计

python之Django CentOS 7之无法导入名称 Col

2024年10月25日22lautakyan007

我已经在 CentOS 7.0 版本上安装了 Django。

#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

原来是这样的

请您参考如下方法:

我在安装 Django 时遇到了同样的问题,事实证明 fields.py 是我从(可能不正确地)降级的较新版本的 Django (1.7.x) 中遗留下来的。我卸载了 Django,删除了 site-packages 下剩余的 Django 目录,然后重新安装它,问题就解决了。