Django-widget-tweaks : ModuleNotFoundError: No module named 'widget_tweaks' - django

I am new to Django and also github CI/CD pipelines. I am working on a django project and I installed widget_tweaks via pip install django-widget-tweaks on the command prompt. The program and forms are working fine on the browser with no errors. However, I have a ci/cd pipeline on github to automate testing and when I try push the code, I get the following error:
Run pip3 install --user django
Collecting django
Downloading https://files.pythonhosted.org/packages/75/42/f59a8ebf14be6d17438f13042c775f53d3dfa71fff973e4aef64ca89582c/Django-3.1.6-py3-none-any.whl (7.8MB)
Collecting pytz (from django)
Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
Collecting sqlparse>=0.2.2 (from django)
Downloading https://files.pythonhosted.org/packages/14/05/6e8eb62ca685b10e34051a80d7ea94b7137369d8c0be5c3b9d9b6e3f5dae/sqlparse-0.4.1-py3-none-any.whl (42kB)
Collecting asgiref<4,>=3.2.10 (from django)
Downloading https://files.pythonhosted.org/packages/89/49/5531992efc62f9c6d08a7199dc31176c8c60f7b2548c6ef245f96f29d0d9/asgiref-3.3.1-py3-none-any.whl
Installing collected packages: pytz, sqlparse, asgiref, django
Successfully installed asgiref-3.3.1 django-3.1.6 pytz-2021.1 sqlparse-0.4.1
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/runner/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/runner/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/runner/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/runner/.local/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/runner/.local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'widget_tweaks'
Error: Process completed with exit code 1.
My ci.yml file for the ci/cd pipeline looks like this:
name: Testing
on: push
jobs:
test_project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Run Django unit tests
run: |
pip3 install --user django
python3 manage.py test

SOLVED: I added "pip3 install django-widget-tweaks" to the ci.yml file for the github CICD pipeline

Related

Deploying 'Django for beginners' app to Heroku fails with ModuleNotFoundError: No module named '_tkinter'

I am following William Vincents Django for Beginners, and I'm about to push the blog app to Heroku at the end of chapter 8. I have checked the code several times, and everything is just as in the book, but it fails every time with ModuleNotFoundError: No module named '_tkinter'. Here is the log from Heroku:
-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> Using Python version specified in runtime.txt
! Python has released a security update! Please consider upgrading to python-3.10.4
Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.10.3
-----> Installing pip 22.0.4, setuptools 60.10.0 and wheel 0.37.1
-----> Installing SQLite3
-----> Installing requirements with pip
Collecting asgiref==3.5.0
Downloading asgiref-3.5.0-py3-none-any.whl (22 kB)
Collecting Django==4.0.4
Downloading Django-4.0.4-py3-none-any.whl (8.0 MB)
Collecting gunicorn==20.1.0
Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
Collecting sqlparse==0.4.2
Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
Collecting tzdata==2022.1
Downloading tzdata-2022.1-py2.py3-none-any.whl (339 kB)
Collecting whitenoise==5.3.0
Downloading whitenoise-5.3.0-py2.py3-none-any.whl (19 kB)
Installing collected packages: whitenoise, tzdata, sqlparse, gunicorn, asgiref, Django
Successfully installed Django-4.0.4 asgiref-3.5.0 gunicorn-20.1.0 sqlparse-0.4.2 tzdata-2022.1 whitenoise-5.3.0
-----> $ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "/tmp/build_8fe73f22/manage.py", line 22, in <module>
main()
File "/tmp/build_8fe73f22/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/tmp/build_8fe73f22/blog/models.py", line 1, in <module>
from tkinter import CASCADE
File "/app/.heroku/python/lib/python3.10/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
The error shows that you have this in your blog/models.py:
from tkinter import CASCADE
That line certainly shouldn't be there. Tkinter is a graphical toolkit, and using it in any capacity in a Django project would be very unusual.
I suspect you are using an IDE that is "helpfully" guessing about missing imports and automatically adding them, probably because you typed CASCADE somewhere else in that file.
Remove that line (and any other imports you don't need, especially ones related to Tkinter), commit, and redeploy.

creating django project just doesnt work right

i create a project folder, than create a venv and do $ django-admin startproject trydjango.
now when i try to run runserver it gives me an error that it couldnt find manage.py, so i have to move it to the original project folder (which now has venv, trydjango, and manage.py). this is a problem i have seen online.
however, when i try to run runserver now it says:
"ModuleNotFoundError: No module named 'trydjango.settings'"
(full traceback below)
the weird thing is, i have opened a project file just like this before, but now its not working. i have done it in the exact same way, the exact way that tutorials show. the only thing that changed is the django version - the tutorial said to use 2.0.7 in order to be able to follow the tutorial.
full traceback:
Traceback (most recent call last):
File "E:\Python\projects\try_django_project\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'trydjango.settings'
I will suggest you doing such way:
Create a virtualenvironment named env or venv or as your wish and activate it.
Then install django via pip install django
now run this command django-admin startproject trydjango You can
see you project structure such way:
-env
-trydjango
--trydjango
--manage.py
Now enter the project directory where manage.py stays and run python manage.py runserver
Hope this will work for you.

Dokku Compilation Error - django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

I've been attempting to setup my built-up Django Instance as a Database Server. Had chosen DigitalOcean as my platform and had read that Dokku is a useful PaaS system that will enable better scalability for this API I'm trying to deploy.
I have been at this problem for the last 3-4 days straight and really had gone through every potential means of solution I could have found online.
Being more of a front-end developer, I'm pretty bad at this backend installation matter.
At first I thought that Dokku was sort of a Git-push function where I will push from localhost -> Dokku -> Git -> Deploy.
Digging deep, I setup Public-Private keys for Dokku to authorize a Git push to Github.
Ultimately, after finally giving up on that route, I did realised I was in the wrong and roughly the way Dokku should work is localhost -> Git push -> Dokku -> Deploy.
Been at this for the last 15-18 hrs of development. The flow seemed to work, where I didn't really need to do much installations on the DigitalOcean droplet.
However, the biggest issue I am facing is with this
My current install is as so:
DigitalOcean Droplet 1-click Dokku VERSION 0.14.6
OS Ubuntu 18.04
I have added all suggested files as I have found in online blogs and forums of the following under the root folder:
requirements.txt
---
absl-py==0.4.0
astor==0.7.1
backports.weakref==1.0.post1
dj-database-url==0.5.0
Django==1.11.20
django-cors-headers==3.0.0
django-filter==2.0.0
djangorestframework==3.9.4
enum34==1.1.6
funcsigs==1.0.2
futures==3.2.0
gast==0.2.0
GDAL==2.4.1
grpcio==1.14.1
h5py==2.8.0
Keras==2.2.2
Keras-Applications==1.0.4
Keras-Preprocessing==1.0.2
Markdown==2.6.11
mock==2.0.0
nose==1.3.7
numpy==1.16.3
pbr==4.2.0
Pillow==6.0.0
protobuf==3.6.1
psycopg2==2.8.2
pytz==2019.1
PyYAML==3.13
scipy==1.1.0
six==1.11.0
sqlparse==0.3.0
tensorboard==1.10.0
tensorflow==1.10.1
termcolor==1.1.0
Theano==1.0.2
virtualenv==16.5.0
Werkzeug==0.14.1
whitenoise==4.1.2
---
runtime.txt
---
<code>python-3.6.8</code>
app.json
---
{
"scripts": {
"dokku": {
"postdeploy": "./manage.py migrate"
}
}
}
---
Procfile
---
web: gunicorn core.wsgi — log-file -
---
settings.py
---
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': 'dbpassword',
'HOST': 'localhost',
'PORT': '5432',
},
'original': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
I was expecting after typing "git push dokku master" the compilation will give me a deployment url which I can view and launch the Django server.
However, what I was face was:
Enumerating objects: 8664, done.
Counting objects: 100% (8664/8664), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5363/5363), done.
Writing objects: 100% (8664/8664), 17.23 MiB | 3.67 MiB/s, done.
Total 8664 (delta 2186), reused 8568 (delta 2157)
remote: Resolving deltas: 100% (2186/2186), done.
-----> Cleaning up...
-----> Building apihirebred from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Python app detected
-----> Installing python-3.6.8
-----> Installing pip
-----> Installing dependencies with Pipenv 2018.5.18…
Installing dependencies from Pipfile…
-----> Noticed GDAL. Bootstrapping gdal.
-----> $ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
More specifically:
"django.core.exceptions.ImproperlyConfigured: Error loading
psycopg2 module: No module named 'psycopg2'" error, that kept on
persisting no matter how I have tried to resolve the bug. : : ! [remote rejected] master -> master (pre-receive hook
declined) error: failed to push some refs to 'dokku#server'
No matter how I have tried to install on both Dokku and my localhost for "psycopg2", I was unable to resolve the bug.
I sincerely hope someone can assist me with the above, as I am no expert on this matter with Dokku or how it really compiles the package and why the compiler is unable to retrieve "psycopg2" for the deployment.
I also hope this will not be the only issue moving forward as well.
Hope to hear your expert advice. Thanks!
try this docker command to install psycopg2 adapter
docker-compose exec web pipenv install psycopg2-binary==2.8.3
you can also mention your own specific version if you like.
if you still get an error it means the container is not stopped properly. Use below command to stop it
docker-compose down
and then start it after installing psycopg2
docker-compose up

No module named 'social_django' when creating superuser

I'm running a django project and I get this error when I try to add a superuser with the command
python manage.py createsuperuser
the error I get is
>File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
>File "/home/boidot/anaconda3/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
>File "/home/boidot/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
>File "<frozen importlib._bootstrap>", line 994, in _gcd_import
>File "<frozen importlib._bootstrap>", line 971, in _find_and_load
>File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'social_django'
howerever I think I installed all the required packages in a virtual environment.
the result of pip freeze
certifi==2018.1.18
chardet==3.0.4
click==6.7
dash==0.19.0
dash-core-components==0.14.0
dash-html-components==0.8.0
dash-renderer==0.11.1
dash-table-experiments==0.5.4
decorator==4.2.1
defusedxml==0.5.0
Django==2.0.2
django-admin==1.1.1
django-excel-response2==2.0.8
django-six==1.0.4
django-social-auth==0.7.28
Flask==0.12.2
Flask-Compress==1.4.0
httplib2==0.10.3
idna==2.6
ipython-genutils==0.2.0
itsdangerous==0.24
Jinja2==2.10
jsonschema==2.6.0
jupyter-core==4.4.0
MarkupSafe==1.0
nbformat==4.4.0
numpy==1.14.0
oauth2==1.9.0.post1
oauthlib==2.0.6
panda==0.3.1
pandas==0.22.0
plotly==2.3.0
PyJWT==1.5.3
python-dateutil==2.6.1
python-openid==2.2.5
python-social-auth==0.3.6
python3-openid==3.1.0
pytz==2017.3
requests==2.18.4
requests-oauthlib==0.8.0
screen==1.0.1
six==1.11.0
social-auth-app-django==2.1.0
social-auth-core==1.6.0
traitlets==4.3.2
urllib3==1.22
Werkzeug==0.14.1
xlwt==1.3.0
I don't have the social_django in the pip freeze result, however when I run
pip3 install social_django I get
Could not find a version that satisfies the requirement social_django (from versions: )
No matching distribution found for social_django
I've tried other commands of the manage.py file (like the basic shell) and I get the same errors. Can you help ?
Social_Django is module of "social-auth-app-django"
so just run this command
pip install social-auth-app-django
If you want to use social auth, then you also need to install django app.
pip install python-social-auth[django]

python-social-auth with Django: ImportError: No module named 'social_django'

ALL packages installed!!
Hi, I'm using python 3.5 Django==1.10 I installed Python-social-auth executed the command Python manage.py transfer error received!
Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django
/core/management/init.py", line 367, in execute_from_command_line
utility.execute()
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/core/management/init.py", line 341, in execute
django.setup()
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/init.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 665, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/social/apps/django_app/default/models.py", line 1, in
from social_django.models import AbstractUserSocialAuth, UserSocialAuth, Nonce, Association, Code, DjangoStorage
ImportError: No module named 'social_django'
To use Django with python social auth, you need to install the Django app as well.
You can specify that you want to install the extra requirements for Django when you install python-social-auth:
pip install python-social-auth[django]
Or, in this case, you can install the missing package individually:
pip install social-auth-app-django
Probably you should use pip 3:
pip3 install social-auth-app-django
USE pip install python-social-auth[django] instead of pip install python-social-auth while installing
i have
first done install
pip install python-social-auth
Run
error: No module named 'social_django'
Then i install
pip install python-social-auth[django]
RUN
Operations to perform:
Apply all migrations: admin, auth, contenttypes, music, sessions, social_django
Running migrations:
Applying social_django.0001_initial... OK
Applying social_django.0002_add_related_name... OK
Applying social_django.0003_alter_email_max_length... OK
Applying social_django.0004_auto_20160423_0400... OK
Applying social_django.0005_auto_20160727_2333... OK
Applying social_django.0006_partial... OK
Running migrations:
For extra support
Migrating from python-social-auth to split social
enter link description here
If you are using pipenv like me don't forget to enter the shell and then install (I forgot to do so and it caused similar errors):
pipenv shell
pipenv install python-social-auth-app-django
then add social_django to install apps
I understand this wasn't the original question but hope it helps.
Just run:
pip install social-auth-app-django