ImportError: Couldn't import Django

前端 未结 22 1802
无人共我
无人共我 2020-12-05 01:59

I\'ve already configured virtualenv in pycharm, when using the python manage.py command, this is error shown:

E:\\video course\\Python\\code\\web_worker\\MxO         


        
相关标签:
22条回答
  • 2020-12-05 02:37

    If you are working on a machine where it doesn't have permissions to all the files and moreover you have two versions such as default 2.7 & latest 3.6 then while running the command use the python version with the command. If the latest python is installed with sudo then run the command with sudo.

    exp:

    sudo python3.6 manage.py runserver
    
    0 讨论(0)
  • 2020-12-05 02:37

    I had same problem, I installed all dependencies with root access :

    In your case:

    sudo pip install django

    In my case, I had all dependencies in requirements.txt, So:

    sudo pip3 install -r requirements.txt

    0 讨论(0)
  • 2020-12-05 02:38

    If you are using python 3 use py in front of cmd code, like this

    py manage.py runserver
    
    0 讨论(0)
  • 2020-12-05 02:39
    1. Check that you have installed Django; by executing import django in python. you mustn't see ModuleNotFoundError if everything's ok.

    2. Check that you have installed virtualenv; by executing virtualenv --version. you must see the version number if everything's ok.

    3. Check that you have enabled virtualenv; there's got to be the name of your virtualenv in your command prompt starting line. enable it by source bin/activate. also, remember to deactivate it every time your job is finished with the virtualenv.

    4. Check that your virtualenv includes django. a virtualenv by default has no modules installed. you either have to install django in your virtualenv (even if you have it in your machine already) or use virtualenv --system-site-packages when creating a virtualenv to include system site packages in the virtualenv.

    5. Add django to your path. open python, import django, then run django to see django's path. then add it to your ~/.bashrc (or ~/.zshrc if you're using zsh). more info in here

    6. Install django-admin by running pip install django-admin

    0 讨论(0)
  • 2020-12-05 02:39

    I was having great difficulties with this but I have solved my issue. I am on Windows 10 using Vagrant ssh in my virtualenv environment, the box I have installed is ubuntu/xenial64, Django version 2.1, python==3.6.

    When I was installing packages I was using pip3 but most importantly I was using sudo and the -H flag to install these packages. When I ran sudo pip3 freeze my packages would come up, but when I ran a plain pip3 freeze there would be no packages.

    Then I tried the python3 manage.py startapp <YOUR APP NAME> and it did not work same error as you.

    I finally thought to try sudo python3 manage.py startapp <YOUR APP NAME> it finally worked!

    Hope this was help :)

    0 讨论(0)
  • 2020-12-05 02:39

    find your django parent dir path and add it to PYTHONPATH

    In my case, my django parent dir path is /Library/Python/3.7/site-packages,add this line into ~/.bash_profile

    export PYTHONPATH=/Library/Python/3.7/site-packages
    

    else if you have PYTHONPATH already, just append it like this

    export PYTHONPATH=${PYTHONPATH}:/Library/Python/3.7/site-packages
    

    then

    source ~/.bash_profile
    
    0 讨论(0)
提交回复
热议问题