Running django in virtualenv - ImportError: No module named django.core.management?

后端 未结 8 831
情歌与酒
情歌与酒 2021-02-04 11:56

I have installed Django after activating my virtualenv but still I am getting following error

from django.core.management import execute_from_command_line
Import         


        
相关标签:
8条回答
  • 2021-02-04 12:16

    I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.

    I confirmed that I was using the python interpreter in my virtual environment.

    I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.

    0 讨论(0)
  • 2021-02-04 12:24

    I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command python manage.py shell without first switching to the venv.

    The problem was resolved after I switched back.

    0 讨论(0)
  • 2021-02-04 12:25

    I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.

    0 讨论(0)
  • 2021-02-04 12:27

    I am using virtual environment so I added this line in manage.py:

    sys.path.append('./myvenv/lib/python3.5/site-packages')
    

    in which myvenv is the name of my virtual environment and version of my installed Python is 3.5. This solved my issued.

    0 讨论(0)
  • 2021-02-04 12:29
     sudo pip install django --upgrade
    

    worked for me, i am not having virutal environment by the way.

    0 讨论(0)
  • 2021-02-04 12:32

    If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.

    pip install django
    

    With next command you can see if Django was installed.

    pip freeze | grep django
    

    Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.

    0 讨论(0)
提交回复
热议问题