我正在做一个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)
2条答案
按热度按时间n1bvdmb61#
字符串
我通过升级Django解决了这个问题。如果有人得到psycopg 2错误,则运行
型
或安装psycopg-binary
型
oxalkeyp2#
这个代码有效
字符串