从django.core.management导入execute_from_command_line不工作

g52tjvyc  于 2023-08-08  发布在  Go
关注(0)|答案(2)|浏览(183)

我正在做一个bug项目。它在Python 2.7上,我们正在迁移到Python 3.9。在manage.py导入from django.core.management import execute_from_command_line期间,我在www.example.com中收到导入错误。对于Python 2.7来说,它很好,但对于Python 3来说,它不起作用。我已经为Python 3创建了单独的虚拟环境。
manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "best_buy_mall.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

字符串
目录树:my_app/django_site/manage.py
my_app/venv(对于python 2)
my_app/v_env(对于python3)

n1bvdmb6

n1bvdmb61#

sudo pip install django --upgrade

字符串
我通过升级Django解决了这个问题。如果有人得到psycopg 2错误,则运行

sudo pip install psycopg2 --upgrade


或安装psycopg-binary

sudo pip install psycopg2-binary --upgrade

oxalkeyp

oxalkeyp2#

这个代码有效

sudo apt-get update

字符串

相关问题