Import Error: No module named django

后端 未结 7 1540
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 07:34

I am using centos linux.

I had python 2.6 with django and now i upgraded to python 2.7.
Python 2.6 is located in /usr/lib/python2.6.
Python 2.7 is located i

相关标签:
7条回答
  • 2020-11-30 07:57

    django went missing with an upgrade to python 3.7

    pip3 install django
    

    fixed the problem.

    0 讨论(0)
  • 2020-11-30 08:07

    To check your path, you can use the following code:

    import sys     
    print(sys.path)
    

    If you already know where django is installed, it should be easy to test if the desired directory is in your path with directory in sys.path.

    Regarding where your PYTHONPATH is defined, note that it's an environment variable, so you can check its value (if defined) with: echo $PYTHONPATH

    0 讨论(0)
  • 2020-11-30 08:07

    If you are using a enviroment use:

    $ ~/Documents/backend/environment/bin/python -m mypy ~/Documents/backend/src/file.py
    
    0 讨论(0)
  • 2020-11-30 08:16

    Try printing sys.path to see what's in your path. Django need to be in one of the dirs listed. Example on Windows:

    >>> import sys
    >>> for p in sys.path: print p
    
    C:\Python27\Lib\idlelib
    C:\Windows\system32\python27.zip
    C:\Python27\DLLs
    C:\Python27\lib
    C:\Python27\lib\plat-win
    C:\Python27\lib\lib-tk
    C:\Python27
    C:\Python27\lib\site-packages
    >>> 
    
    0 讨论(0)
  • 2020-11-30 08:18

    I had the same error, and this fix my issue

    python -m pip install django

    :) Done!

    0 讨论(0)
  • 2020-11-30 08:19

    try

    pip freeze
    

    this command show which packages are installed in your system then run with root privilege

    pip install django
    

    then create a new project with command

    django-admin.py startproject mysite
    

    then start your project

    cd path/to/mysite
    ./manage.py runserver 
    

    in file wsgi.py add this lines

    import os
    import sys
    DJANGO_PATH =  os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
    sys.path.append(DJANGO_PATH)
    
    0 讨论(0)
提交回复
热议问题