在Ubuntu 18下创建django项目,运行python文件时报错:
SyntaxError: Non-ASCII character '\xe9' in file /home/image/桌面/django_test/test_proj/
test_proj/settings.py on line 127, but no encoding deared; see http://python.org/dev/
peps/pep-0263/ for details
或者有时候明明安装了响应的package但是还是会提示No module named xxx
实际上ubuntu下默认安装了python2.7,在启动python和pip时都有不同,安装package也是分开安装的:
可以输入pip -V和python -V命令来查看区别:
image@ubuntu:~/桌面/django_test/test_proj$ pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
image@ubuntu:~/桌面/django_test/test_proj$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
image@ubuntu:~/桌面/django_test/test_proj$ python -V
Python 2.7.17
image@ubuntu:~/桌面/django_test/test_proj$ python3 -V
Python 3.6.9
所以安装和启动python程序的时候使用对应的python和pip就不会报错了:
pip3 install xxx
python3 xxx.py