ModuleNotFoundError: No module named 'rest_framework' - django

I'm trying to follow a tutorial on DRF, but when I'm about to run "migrate" for the database, i get
ModuleNotFoundError: No module named 'rest_framework'.
As PyCharm hints, the same also applies to django_summernote and djoser I have there.
I know there are some threads like this, but nothing from those seems to help - the Python console DOES recognize these modules, and they are added through INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'kursovik.apps.KursovikConfig',
'rest_framework',
'rest_framework.authtoken',
'django_summernote',
'djoser',
'kursovik']
I recently downloaded these through
pip install djangorestframework
pip install djoser
pip install django-summernote
do i need to reinstall them?

You have to ensure that your PyCharm console uses the correct Python Path where the packages are available basically so to say.
Go to File/Settings/YourProject and check for the following:
Set the correct path to make the packages available for interpretation procedures.

If you have already install restframework but still encounter this issue, try this method, this is to install rest in you venv
In your project folder (by sys.executable to find)
In command line:
1)source bin/activate
(then start to install rest framework)
2)pip install djangorestframework
3)deactive
then restart pycharm.

Related

No module named 'mysite.settings'

I know this question has been asked quite a lot but all the solutions given do not seem to fit for me.
I run this in a venv with python 3.6.8 and django 2.2.10
When I run django from cli it works and all functionality is working great so I know it is not django itself that is failing me.
Path to wsgi script is "/opt/sites/aws/okta/wsgi.py"
Actual wsgi.py:
import os, sys
sys.path.append('/opt/sites/aws')
#path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#sys.path.append(path)
print(sys.path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "okta.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
When running python to see what errors it gives I get
ModuleNotFoundError: No module named 'okta.settings'
I get the same error when running apache with debug logging.
I have quadruple checked the path and the environment variables and they are set right in the wsgi.py script.
Asked for the INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'okta_oauth2.apps.OktaOauth2Config',
'ops.apps.OpsConfig'
]
aws/
bin/
lib/
lib64/
logs/
okta/
__init__.py
urls.py
settings.py
wsgi.py
okta_oauth2/
ops/
share/
static/
manage.py
pyvenv.cfg
Although I did not figure out what was wrong. This is what I did to resolve.
Note for anyone reading this in the future, please DO NOT do this first. I tried other more common results like ImportError: No module named mysite.settings (Django) to fix the issue first and when none worked I tried this.
cd /opt/sites #Just outside the venv
sudo service httpd stop # stop web server
mv aws aws_broken_20201223 # move your broken env to a new name but do not delete
python3 -m venv aws #create new venv
cp -R aws_broken_20201223/(django dirs) aws/ #copy all the custom apps and project you have to the new folder
cd aws #go to the new install
bin/activate #activate your env
pip 3 install -r requirements.txt # I had a predefined requirements.txt for all mods I needed. I would suggest you do the same before doing this.
python3 okta/wsgi.py # Test to see if you are still getting the not found error
sudo service httpd start # start web server back up
voila it works without issue, no config change at all. Very strange but I'll take a working production site then a broken one.

unable to install django restframework.auth_token

Trying to install from source
git clone https://github.com/tomchristie/django-rest-framework.git
cd django-rest-framework
setup.py install
settings.py
INSTALLED_APPS = (
...
'rest_framework.authtoken',
'rest_framework',
...
)
Trying to migrate
manage.py migrate
WindowsError: [Error 3] The system cannot find the path specified:
'C:\\Python27\\lib\\site-packages\\djangorestframework-3.0.0-py2.7.egg\\rest_framework\\authtoken\\migrations/*.*'
Whats the problem here ? Why is this a windows error ?
(rest_framework is migrating just fine ... )
Thanks.
I ended up copying the actual folder i cloned into c:\Python27\lin\sitepackages and renamed it to ...*.egg. It worked.

django.core.exceptions.ImproperlyConfigured:constance.backends.database app isn't installed correctly

Hi I am setting up my django with virtualenv
When I run python manage.py migrate, I got this error.
File "/Users/anh/testRadicards/env/lib/python2.7/site- packages/constance/backends/database/init.py", line 27, in init
"The constance.backends.database app isn't installed "
django.core.exceptions.ImproperlyConfigured: The constance.backends.database app isn't installed correctly. Make sure it's in your INSTALLED_APPS setting.
This is my setup, running with Mac OSX 10.5, on Python 2.7:
1. cd into my project dir
2. run virtualenv --no-site-packages env
3. activate my virtualenv with source/env/bin/activate
4. pip install django (currently 1.7.1)
5. git clone a django project repo called radicards
6. cd into radicards
7. run python.manage.py runserver
(The repo radicards already have a sqlite db setup, so there's no need for migration).
I followed the error code and open settings.py and it include this:
INSTALLED_APPS = (
'constance',
'constance.backends.database',
'rd_suit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'paintstore',
'cards',
)
'Contance.backends.database' is included. I heard django 1.7 has some issues with unique name error.
What should I do? To set this up.
Try adding this setting to your settings.py file:
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'

Django-mptt error. Can't find admin/mptt_change_list.html template

I\ve got a problem similar to this topic Django-MPTT, how to
I've added 'mptt' to INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
'south',
'mptt',
)
But steel I have this error
TemplateDoesNotExist at /admin/app/category/
admin/mptt_change_list.html
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/app/category/
Django Version: 1.6.5
Exception Type: TemplateDoesNotExist
Exception Value:
admin/mptt_change_list.html
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/loader.py in find_template, line 131
Python Executable: /usr/bin/python
Python Version: 2.7.6
It seems that template is not on it's path, but mptt is installed correctly and is on PYTHONPATH
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/mptt_change_list.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/admin/mptt_change_list.html (File does not exist)
/home/islam/DM/repo/dm/DM-165/app/templates/admin/mptt_change_list.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/debug_toolbar/templates/admin/mptt_change_list.html (File does not exist)
The solution was to delete mptt using sudo pip uninstall django-mptt
and install it again using pip: sudo pip install django-mptt --upgrade
Well as for as i know you can install Any python django package there easy ways:
1.)
You can do like via
pip install <package Nmae>
for sometime sudo pip install <packageName> also works
2.)
Then download the tar file and extract from that directory you can install via
python setup.py insatll
3.)
And here you did two so try this thing also
download the mptt folder and put it into your django project. Hope this will work

How do I refer to packages installed via pip in a virtual enviroment in INSTALLED_APPS?

When I create a new app in a Django project via python manage.py startapp polls I then simply add it to my list of installed apps:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'survy',
)
However when I install an application such as django-countries via PIP pip install django-countries into a virtual environment is there a different or better way to add it to the list of installed apps?
I have simply been using the same method and I think it might be wrong, thus contributing to the issue having in my other question.
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'survey',
'django_countries',
)
This is giving me no errors but I am not sure if it working right.
NOTE: as per the pip page and this SO question, the package is called django-countries but I believe it should be referred to as django_countries in INSTALLED_APPS.
No, you are right. You just need to add the module name, as if it was one of your module.
Django searches apps in your Python path and it will take the first module it find. Since Django third-parties are installed in site-packages generally (the one of the virtualenv in your case) and this folder is in your Python path, Django will act as usual with these modules.