Django Rest Framework — no module named rest_framework

后端 未结 21 808
夕颜
夕颜 2021-02-01 00:23

I\'ve installed django rest framework using pip install djangorestframework yet I still get this error when I run \"python3 manage.py sycndb\":

相关标签:
21条回答
  • 2021-02-01 00:52

    if you used pipenv:

    if you installed rest_framework thru the new pipenv, you need to run it thru the virtual environment:

    1.pipenv shell

    2.(env) now, run your command(for example python manage.py runserver)

    0 讨论(0)
  • 2021-02-01 00:54

    I've faced the same problem, followed these instructions and it worked for me:

    1. python -m pip install --upgrade pip (to upgrade pip)
    2. pip3 install djangorestframework
    3. Added rest_framework as first app:

      INSTALLED_APPS = [
          'rest_framework',
          'django.contrib.admin',
          'django.contrib.auth',
          'django.contrib.contenttypes',
          'django.contrib.sessions',
          'django.contrib.messages',
          'django.contrib.staticfiles',
          #apps
          'apps.endpoints',
      ]
      
    0 讨论(0)
  • 2021-02-01 00:56

    If you're using some sort of virtual environment do this!

    1. Exit from your virtual environment.

    2. Activate your virtual environment.

    After you've done this you can try running your command again and this time it probably won't have any ImportErrors.

    0 讨论(0)
  • 2021-02-01 00:58

    Maybe you install DRF is for python2, not for python3.

    You can use python console to check your module:

    import rest_framework
    

    Actually you use pip to install module, it will install python2 module.

    You should install the pip for python3:

    sudo apt-get install python3-setuptools
    sudo easy_install3 pip
    

    So, you can install python3 module.

    0 讨论(0)
  • 2021-02-01 00:58
    INSTALLED_APPS = [
    'rest_framework',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #apps
    'apps.endpoints',
    

    ]

    maybe forgot the comma "," or while pasting packing name it might have extra whitespace "packagename "check for that

    0 讨论(0)
  • 2021-02-01 01:00

    Yeh for me it was the python version as well ...
    much better to use pipenv ...
    create a virtual env using using python 3 ...

    install pipenv : pip3 install pipenv
    create the virtualenv: pipenv --python 3
    activate the virtual env: pipenv shell

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