把Django Book看了一遍之后,就一直在写Flask;
今天准备用Django写个仿知乎网站,却发现以前的venv环境下启动Django一直报错:
首先是报:
command not found: django-admin.py
command not found: django-admin
在stackoverflow上查到了解决方法,需要将Python的目录添加到环境变量中去,用软连接连过去就好:
ln -s /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/bin/django-admin.py /usr/local/bin
然后用:
django-admin startproject zheye
又报出如下错误:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 2, in <module>
from django.core import management
经过查看django-admin.py里的内容:
nano /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/bin/django-admin.py
发现首行这里有问题:
#!/usr/bin/env python
将Python改python3就可以正常导入了,原因是Python path里用的是默认的python2.6、2.7