简体   繁体   English

正在运行服务器错误:“ ImportError:没有名为'django'的模块”在OS-X中

[英]Running server error: “ImportError: No module named 'django'” in OS - X

I'm attempting to start up my first Django project. 我正在尝试启动我的第一个Django项目。 I have virtualenv setup and running with Django 1.8.5 installed. 我已经安装了virtualenv并与Django 1.8.5一起运行。 When I run pip freeze within my virtualenv I get: 当我在virtualenv中运行pip freeze ,我得到:

Django==1.8.5  
wheel==0.24.0

I then CD into my project and run python manage.py runserver and get an error: 然后,我将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'

I opened up my manage.py file and it contains: 我打开了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)

Pip list: 点列表:

Django (1.8.5)
pip (7.1.2)
setuptools (18.2)
wheel (0.24.0)

I have attempted starting multiple projects, all give the same error. 我尝试启动多个项目,但都给出相同的错误。 I have tried both with and without virtualenv (Django is also installed globally) to no avail. 我尝试了和没有virtualenv(Django也已全局安装)都无济于事。 I've done a lot of research but haven't found any answers that fix my issue. 我已经做了很多研究,但是还没有找到解决我问题的答案。

EDIT When stating up a new virtualenv and running source bin/activate for the first time I get the following message: 编辑当陈述一个新的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

first ,you can also try this command. 首先,您也可以尝试此命令。

python3 manage.py runserver

According to my experience, I think your trouble caused to some packages miss matching reason.so , It is better check documentation ,If you do every thing correctly. 根据我的经验,我认为您的麻烦是由于某些软件包缺少匹配原因造成的。所以,最好检查一下文档,如果正确地做每件事。 please , check Django official site. 请检查Django官方网站。

I have lot of experience about work with OS-X. 我有很多使用OS-X的经验。 because I work in UBUNTU 14.04.This some example I , installed Django.you can refer it. 因为我在UBUNTU 14.04中工作。这个示例我安装了Django。您可以参考它。 install Django with mongoDB 使用mongoDB安装Django

I will successfully , install using following tutorials.I recommend you also refer that and reinstall . 我将成功完成安装,请使用以下教程。建议您同时参考并重新安装。

Django Girls Tutorial Django女孩教程

About django 关于django

=====================Answer to your comment==================== ===========================================

I realize, your computer have Install both python 2.x and python 3.x. 我知道,您的计算机已经安装了python 2.x和python3.x。 Default run python 2.x. 默认运行python2.x。 when you create virtual environment , default it make it for python 2.x. 创建虚拟环境时,默认情况下将其用于python2.x。 so , you should specify python version when create virtual environment.As I remember Django 1.8 not support to python 2.x. 因此,您应该在创建虚拟环境时指定python版本。我记得Django 1.8不支持python2.x。 I think now , you received some answer. 我想现在,您收到了一些答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM