ModuleNotFoundError: No module named 'widget_tweaks' - python

I'm writing project using docker and django (2.1).
I've installed module 'django-widget-tweaks' inside a container and added 'widget_tweaks' to INSTALLED_APPS. When I start project using docker-compose up everything works well, but when I want to run something like docker-compose run <container name> python manage.py test in another terminal an error occurs.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/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'
But when I directly run the same command python manage.py test inside a docker container, it works. widget-tweaks has been installed both on container and on my machine. Could you advice something to solve the problem?
Thanks in advance!

Related

Django on Heroku: KeyError: 'collectstatic'

I'm trying to deploy my simple Django web app on Heroku, but the build fails with the following error:
Successfully installed asgiref-3.3.4 dj-database-url-0.5.0 django-3.2 django-heroku-0.3.1 gunicorn-20.1.0 numpy-1.20.2 pillow-8.2.0 psycopg2-2.8.6 pytz-2021.1 sqlparse-0.4.1 torch-1.8.1 torchvision-0.9.1 typing-extensions-3.7.4.3 whitenoise-5.2.0
-----> $ python pytorch_django/manage.py collectstatic --noinput
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 237, in fetch_command
app_name = commands[subcommand]
KeyError: 'collectstatic'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/build_6b3954ac/pytorch_django/manage.py", line 22, in <module>
main()
File "/tmp/build_6b3954ac/pytorch_django/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 244, in fetch_command
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.9/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 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
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 'project'
! Error while running '$ python pytorch_django/manage.py collectstatic --noinput'.
I have successfully deployed other Django apps on Heroku and I don't get what's wrong here. What does KeyError: 'collectstatic' mean or where does it come from?
Locally, the app runs fine and also python manage.py collectstatic runs fine. What's the problem? Could it be related to Python 3.9? I have Python 3.8 locally.
Edit: This also happens with a freshly created Django app - no changes in the code whatsover.
The problem was my own fault but not in the Django app but in my Heroku configuration.
Inside my Heroku environmental variables (Settings > Config Vars), I had set the DJANGO_SETTINGS_MODULE incorrectly to project.prod_settings.
However, my Django project was called pytorch_django so I had to set it to pytorch_django.prod_settings.
That's what caused the error ModuleNotFoundError: No module named 'project'.
Changing DJANGO_SETTINGS_MODULE to the correct path solved the problem.

Django No module named 'responsive_images'

Getting the following error when ported Django from 2.7 to 3.6
Traceback (most recent call last):
File "manage.py", line 21, in <module>main()
File "manage.py", line 17, in main execute_from_command_line(sys.argv)
File "C:\Django\CampusStore\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute()
File "C:\Django\CampusStore\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup()
File "C:\Django\CampusStore\venv\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS)
File "C:\Django\CampusStore\venv\lib\site-packages\django\apps\registry.py", line 91, in populate app_config = AppConfig.create(entry)
File "C:\Django\CampusStore\venv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Python36-32\lib\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 'responsive_images'
You have to make sure you add the library to your INSTALLED_APPS list in settings.py. It's useful to keep in mind the library name as it's downloaded is usually different than it's name in pip. for Example this is installed with pip install django-responsive-images, but responsive_images is what you should include in your INSTALLED_APPS.

Django: ModuleNotFoundError: No module named 'sslserver'

I would like to use https for my Django development server using django-sslserver.
I have installed it using
$ pip install django-sslserver
I have then added it to my settings.py INSTALLED APPS:
INSTALLED_APPS = [
...
'sslserver',
...
]
However, if I now try to start the sslserver like this:
python3 manage.py runssslerver 0.0.0.0:8080
I get the following error:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/pi/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/pi/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/pi/.local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/pi/.local/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/pi/.local/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sslserver'
Any idea how to fix this?
If you are using native python in linux, the pip and pip3 is different. You can try pip3 install django-sslserver.
I recommend to use virtual environment in web service development of python, e.g. pipenv.

python manage.py: No module named 'admin_tools'

I'm trying to run this command on my django project:
python manage.py makemigrations --empty my_app_name
to create a new empty migration.
When I try to run this command in poweshell, I get this message:
PS C:\Travail\workout\workout-backend\workout_rest> python manage.py makemigrations --empty record
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 341, in execute
django.setup()
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'admin_tools'
The error is: ImportError: No module named 'admin_tools'
What am I doing wrong?
I'm on Windows 10 and I'm using VS2017 to developp my Django app.
EDIT:
Something very strange. When I run pip freeze, I get this:
$ pip freeze
astroid==1.4.9
colorama==0.3.7
Django==1.10.3
isort==4.2.5
lazy-object-proxy==1.2.2
mccabe==0.6.1
pylint==1.6.5
six==1.10.0
wrapt==1.10.10
I don't know what are thoses packages. I have no mention of astroid or mccabe in my whole project. Nor in site-package folder, nor in INSTALLED-APP...

Django - Manage.py ModuleNotFoundError: No module named 'mysite' on windows

I'm trying to get Django to work. I installed Django used
django-admin startproject mysite
This created this structure
mysite
-- manage.py
-- mysite
- __init__.py
- settings.py
- etc etc...
now I'm when I run
python manage.py runserver
I get this error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\MySoftware\python361\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\MySoftware\python361\lib\site-packages\django\core\management\__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mysite'
Python cannot find 'mysite'
I've tried PYTHONPATH = 'my director' but so far nothing has worked. Problem seems to be that python cannot find mysite folder
Ok, I'm answering my own question again.
For some strange reason, Python is unable to find the app folder /mysite and even though I set
PYTHONPATH = C:\...\mysite
It did not work
I found a hack to include the directory by inserting this after
import sys
sys.path.append("C:\\xampp\\your\\path\\site1") <--- insert this line (3)
in manage.py, this forces python to look for your app folder when it runs the server. Put the double slashes as well.

Categories

Resources