【问题标题】:Install Django using setup file in Python 2.7在 Python 2.7 中使用安装文件安装 Django
【发布时间】:2017-03-31 08:41:09
【问题描述】:

我正在尝试通过安装文件安装 Diago,然后它显示以下错误:

hari@hari-HP-Pavilion-g6-Notebook-PC:~/Downloads/django-master$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    version = __import__('django').get_version()
  File "/home/hari/Downloads/django-master/django/__init__.py", line 1, in <module>
    from django.utils.version import get_version
  File "/home/hari/Downloads/django-master/django/utils/version.py", line 60, in <module>
    @functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'

如何解决这个错误?

【问题讨论】:

  • 使用pip安装django!
  • pip 也会发生这种情况。问题是 Django 2 不适用于 Python 2.7。要么将 Python 3 与 Django 2 一起使用,要么将 Django 1.11 与 Python 2.7 一起使用

标签: django python-2.7


【解决方案1】:

也许来自 github 的 zip 文件仅适用于 windows,但我看到您使用的是 linux,所以:

1) 使用 PIP(使用 sudo,因为您不在 virtualenv 中)

sudo pip install Django==1.10.6

2) 使用 GIT

git clone https://github.com/django/django.git

希望对你有所帮助

【讨论】:

    【解决方案2】:

    安装Diango时遇到同样的问题
    然后我在 cmd 中使用它

    >>>> import functools  
    >>> dir(functools)
    ['WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', '__builtins__', '__doc__', '__file__'
    , '__name__', '__package__', 'cmp_to_key', 'partial', 'reduce', 'total_ordering'
    , 'update_wrapper', 'wraps']
    

    你可以看到没有lru_cache..so,我想这就是原因..
    然后我安装了Python3.6.1

    >>> import functools
    >>> dir(functools)
    ['MappingProxyType', 'RLock', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', 'WeakKey
    Dictionary', '_CacheInfo', '_HashedSeq', '__all__', '__builtins__', '__cached__'
    , '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_
    c3_merge', '_c3_mro', '_compose_mro', '_convert', '_find_impl', '_ge_from_gt', '
    _ge_from_le', '_ge_from_lt', '_gt_from_ge', '_gt_from_le', '_gt_from_lt', '_le_f
    rom_ge', '_le_from_gt', '_le_from_lt', '_lru_cache_wrapper', '_lt_from_ge', '_lt
    _from_gt', '_lt_from_le', '_make_key', 'cmp_to_key', 'get_cache_token', 'lru_cache', 'namedtuple', 'partial', 'partialmethod', 'recursive_repr', 'reduce', 'sing
    ledispatch', 'total_ordering', 'update_wrapper', 'wraps']
    

    你可以在那里看到lru_cache,我希望它对你有帮助(对不起我的英语,我不擅长这个..)

    【讨论】:

      猜你喜欢
      • 2014-12-22
      • 2012-06-18
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 2017-06-27
      • 2012-04-20
      • 1970-01-01
      相关资源
      最近更新 更多