问题现象:
1.运行环境:centos7.6原环境为python2.7.5,下载了python3后利用python3 -m venv py3命令建立了虚拟环境
2.问题:在虚拟环境里使用python3 manage.py startapp blog命令无法新建名为blog的app,报错如下所示:
(py3) [root@master mysite]# python3 manage.py startapp blog
Traceback (most recent call last):
File "/data/wwwroot/mysite/manage.py", line 22, in <module>
main()
File "/data/wwwroot/mysite/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/py3/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/py3/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/usr/local/py3/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/py3/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/usr/local/py3/lib/python3.9/site-packages/django/apps/config.py", line 224, in create
import_module(entry)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blog'
补充说明:/usr/sbin/firewalld和/usr/bin/firewall-cmd文件里的#!/usr/bin/python已经变更为了#!/usr/bin/python2.7,但问题依然没有解决