我试图启动我的第一个Django项目。我有virtualenv设置和安装Django 1.8.5运行。当我在virtualenv中运行pip freeze
时,我得到:
Django==1.8.5
wheel==0.24.0
然后我将CD放入我的项目并运行python manage.py runserver
并收到错误:
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
我打开了我的manage.py
文件,其中包含:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trydjango18.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
点子列表:
Django (1.8.5)
pip (7.1.2)
setuptools (18.2)
wheel (0.24.0)
我尝试启动多个项目,都给出了同样的错误。无论有没有virtualenv(全局安装Django),我都尝试过无济于事。我做了很多研究,但没有找到解决问题的答案。
编辑当我第一次说明新的virtualenv并运行source bin/activate
时,我收到以下消息:
/Users/master/Desktop/testdjango/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
答案 0 :(得分:0)
首先,你也可以尝试这个命令。
python3 manage.py runserver
根据我的经验,我认为你的麻烦导致一些包装错过匹配的原因。所以,更好的检查文档,如果你做的每件事都正确。请检查Django官方网站。
我在使用OS-X方面有很多经验。因为我在UBUNTU 14.04工作。这个例子我安装了Django.you可以参考它。install Django with mongoDB
我将成功使用以下教程进行安装。我建议您也参考并重新安装。
=====================回答你的评论====================
我意识到,你的电脑安装了python 2.x和python 3.x. 默认运行python 2.x.当你创建虚拟环境时,默认它是为python 2.x。所以,你应该在创建虚拟环境时指定python版本。我记得Django 1.8不支持python 2.x.我想现在,你收到了一些答案。