今天用Pycharm运行一个我以前一直运行的好好的DJango项目时疯狂报错,想了想才知道是之前安装的Python和新安装的Anaconda冲突了。
之前先安装了Python3.6 ,之后又装了Anaconda3,里面有Python3.7。因为安装Anaconda3时选择了自动改变环境变量选项,所以Anaconda所有的相关命令加入到了系统变量path中
如图
而我自己之前安装的Python的环境变量,是我自己手动添加到上方用户变量的path中。系统变量优先级高于用户变量,所以不管我是在cmd命令行还是在Pycharm终端输入python,它都自动执行Anaconda中的python。这就导致我在pycharm运行我以前的项目时,各种报错如下:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
Traceback (most recent call last):
File "manage.py", line 17, in <module>
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?
按照这篇博客的方法改一下变量引用名就好。
https://blog.csdn.net/sinat_41898105/article/details/80660332