简体   繁体   中英

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

I'm attempting to start up my first Django project. I have virtualenv setup and running with Django 1.8.5 installed. When I run pip freeze within my virtualenv I get:

Django==1.8.5  
wheel==0.24.0

I then CD into my project and run python manage.py runserver and get an error:

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:

#!/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. 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:

/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.

I have lot of experience about work with OS-X. because I work in UBUNTU 14.04.This some example I , installed Django.you can refer it. install Django with mongoDB

I will successfully , install using following tutorials.I recommend you also refer that and reinstall .

Django Girls Tutorial

About django

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

I realize, your computer have Install both python 2.x and python 3.x. Default run python 2.x. when you create virtual environment , default it make it for python 2.x. so , you should specify python version when create virtual environment.As I remember Django 1.8 not support to python 2.x. I think now , you received some answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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