python - 启动 Django 项目无效语法

标签 python django python-2.7 django-admin

我正在尝试创建一个新的 Django 项目但正在运行

django-admin startproject myproject

报错

Traceback (most recent call last):
    File "/usr/bin/django-admin", line 7, in <module>
      from django.core.management import execute_from_command_line
    File "/usr/lib64/python2.6/site-packages/django/core/management/__init__.py", line 68
      commands = {name: 'django.core' for name in find_commands(__path__[0])}
                                  ^
SyntaxError: invalid syntax

我肯定缺少一些库,或者某些路径可能无效。但是,我还没有找到解决方案。

我的 Django 文件位于此处:

/opt/.virtualenvs/smart/lib/python2.7/site-packages/django/

最佳答案

您正在使用系统Python启动一个Python2.6项目。并且您已将 Django 1.7 安装到 Python 2.6 环境中,但是 Django 1.7 dropped support for Python 2.6 :

Django 1.7 requires Python 2.7 or above, though we highly recommend the latest minor release. Support for Python 2.6 has been dropped and support for Python 3.4 has been added.

特别是,您看到的错误是由于 Python 2.7 中引入的字典理解语法造成的。

关于python - 启动 Django 项目无效语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27275563/

相关文章:

python - Google Cloud PostgreSQL 实例的主机名是什么?

django - 按差和排序

python - Django Gunicorn导入错误: no module name wsgi

Python 不使用 shell 杀死进程

Python lru_cache 实现

Python字典切换通过其他函数而不仅仅是调用的函数

python - PySide6:加载共享库时出错:libQt6DesignerComponents.so.6:无法打开共享对象文件

python - 使用 Django 信号传递附加属性

python - 如何在 Pandas 中的 "day period"上覆盖数据以进行绘图

python - for 循环遍历 Python 中的一组字符串列表以创建过滤器