How to solve no module error when testing the code? - django

I faced the error No module named 'rest_framework' when testing the code, however rest_framework is installed and everything works just fine. The problem occurs only on tests. When I run pip3 install djangorestframework or python -m pip install djangorestframework , I get this Requirement already satisfied: Everything what I found in the internet did not help. Also I have the following error django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You

Related

cant import flask-wtf after install

I have been looking around for an answer to this question, but everywhere I see the advice of running a pip install flask-wtf in the virtual environment. The requirements have already been satisfied in mine, but for some reason I am getting a missing module error. I am working on a school project building a website using flask and would really appreciate the help. My import is:
from flask_wtf import Form`
When I try to run the install command I get a message that says the requirement is already satisfied, as shown in this image.
Based on the screenshot, your flask-wtf and friends are installed outside virtualenvs, in the system site-packages directory.
It'd be a good idea to uninstall those from the global site-packages directory (python3 -m pip uninstall flask-wtf wtforms flask jinja2 click werkzeug markupsafe itsdangerous), create and activate a virtualenv (python3 -m venv my_venv and ./my_venv/bin/activate), then reinstall the dependencies within the virtualenv.

Heroku and Django 2.x ModuleNotFoundError: No module named 'rest_auth'

I've installed django-rest-auth locally with Django 2.x and it works fine.
However, when I deploy to Heroku I get a "ModuleNotFoundError: No module named 'rest_auth'" error.
I made sure that the requirements.txt is OK (pip freeze).
I also ran commands with CLI and the Heroku CL interface : pip install django-rest-auth
Any ideas why it's not working?
Finally found the answer... I had to add the module ALSO to the pipfile and made sure to adapt the syntax like this :
In requirements.txt => django-rest-auth==0.9.3
In Pipfile => django-rest-auth = "==0.9.3"

Django REST Framework Import Error

I'm trying to install Django REST framework and I keep getting:
No module named 'rest_framework'
I've added:
'rest_framework' to my INSTALLED_APPS = []
I installed through pip3 and it still doesn't seem to be working.
This should not be the case. You might have installed globally or inside virtualenv.
Always installed your dependencies inside a virtualenv.
I think best way to get it working.
source <virtualenv>/bin/activate
pip install djangorestframework
Next whenever you work with your project re-enable back virtualenv.

How to install tldextract on a Python 2.7 app in OpenShift?

Desired Behaviour
To install tldextract (PyPI and GitHub) in a Python 2.7 application on OpenShift.
What I've Tried
I tried adding to setup.py eg:
install_requires=['bottle','pymongo','requests','beautifulsoup4','lxml','Beaker','pycrypto','pillow','tldextract']
And then importing in the application with:
import tldextract
I also tried followed this post and ran the following from the shell:
virtualenv $OPENSHIFT_DATA_DIR/virtualenv --distribute
source $OPENSHIFT_DATA_DIR/virtualenv/bin/activate
pip install tldextract
deactivate
but I get the same error shown below.
This was despite the previous step showing Successfully installed tldextract.
Actual Behaviour
The presence of:
import tldextract
in the application causes a 500 error.
Running tail with:
rhc tail -f app-root/logs/python.log [appname]
The error is:
ImportError: No module named tldextract
Solution
I don't know how or why, but I ssh'ed into shell and ran the following and the ImportError is gone and the desired behaviour is occuring:
source ~/python/virtenv/bin/activate
pip install --log $OPENSHIFT_DATA_DIR/inst.log https://github.com/john-kurkowski/tldextract/archive/master.zip
For reference, setup.py still contains the following but I'm not sure if that is contributing to any functionality:
install_requires=['bottle','pymongo','requests','beautifulsoup4','lxml','Beaker','pycrypto','pillow','tldextract']
Edit
For reference, I was also able to follow the above steps in order to install Pillow.

How to install phonenumbers for Django

there!
I am trying to run an imported app on my Ubuntu. But the error message displayed on the screen says No module named phonenumbers
So I tried to install it, by:
sudo easy_install phonenumbers
But again, it throws error, and says ImportError: No module named shortdata
Then I tried to run
sudo easy_install shortdata
This time it gives me:
error: Could not find suitable distribution for Requirement.parse('shortdata')
I cannot figure out how to install 'shortdata'.
What can I do, to make 'phonenumbers' installed?
The issue happening because the module 'shortdata' is get missing while installation. You can correct the issue by installing from source and manually copy the module 'shortdata'.
1)Download source from https://github.com/daviddrysdale/python-phonenumbers
2)Install phonenumbers using setup.py (python setup.py install)
3)Manually copy folder 'shortdata' from python-phonenumbers-dev/python/phonenumbers in source to your installed location(python2.7/site-packages/phonenumbers-5.7b1-py2.7.egg/phonenumbers)