Please help with the hidden imports issues with django

64 views
Skip to first unread message

David Marceau

unread,
Feb 28, 2024, 6:45:54 PMFeb 28
to PyInstaller
Hi there, I've been struggling to get rid of these hidden imports issues arising from django. Please could you tell me what am I doing wrong? -I have --hidden-import switches -I have tweaked the venv/lib/python3.11/site-packages/PyInstaller/hooks/hook-django.py Line 49 to contain the same list of mentioned hidden imports
Here is exactly what I did with a hello world django sample.
Thank you in advance for any assistance you may provide 🙂 Cheers, David Marceau
David Marceau


source ~/blah/venv/bin/activate
cd /home/paladin/helloworldtests
PYTHONPATH="/home/paladin/blah/common/libraries/python3" /home/paladin/blah/venv/bin/python3.11 -m django startproject hellodjango

cd ~/helloworldtests/hellodjango
PYTHONPATH="/home/paladin/blah/common/libraries/python3" /home/paladin/blah/venv/bin/python3.11 manage.py runserver

/home/paladin/blah/venv/bin/python3.11 -m PyInstaller \
     --clean \
     --debug all \
     --paths /home/paladin/blah/common/libraries/python3 \
     --paths /home/paladin/blah/venv/lib/python3.11/site-packages \
     --hidden-import jinja2.ext \
     --hidden-import django.db.backends.__pycache__.base \
     --hidden-import django.db.backends.oracle.compiler \
     --hidden-import sqlite3.dump \
     --hidden-import django.contrib.staticfiles.templatetags \
     --hidden-import rest_auth.templatetags \
     --hidden-import django.contrib.contenttypes.templatetags \
     --hidden-import django.contrib.staticfiles.context_processors \
     --hidden-import rest_auth.context_processors \
     --hidden-import django.contrib.sessions.templatetags \
     --hidden-import django.contrib.sessions.context_processors \
     --hidden-import tempus_dominus.templatetags \
     --hidden-import tempus_dominus.context_processors \
     --hidden-import dynatrol.templatetags \
     --hidden-import django.contrib.messages.templatetags \
     --hidden-import rest_framework.context_processors \
     --hidden-import rest_framework.authtoken.templatetags \
     --hidden-import multiselectfield.templatetags \
     --hidden-import multiselectfield.context_processors \
     --hidden-import django_json_widget.templatetags \
     --hidden-import django.contrib.admin.context_processors \
     --hidden-import dynatrol.context_processors \
     --hidden-import django.db.backends.postgresql_psycopg2 \
     --hidden-import django.contrib.auth.templatetags \
     --hidden-import rest_framework.authtoken.context_processors \
     --hidden-import django.contrib.contenttypes.context_processors \
     --hidden-import django_json_widget.context_processors \
     --hidden-import http.cookies \
     --hidden-import html.parser \
     --hidden-import mx.DateTime \
     --onefile \
     --name pti-pi-hellodjango manage.py

15052 INFO: Analyzing hidden import 'jinja2.ext'
15052 ERROR: Hidden import 'jinja2.ext' not found
15052 INFO: Analyzing hidden import 'django.db.backends.__pycache__.base'
15052 ERROR: Hidden import 'django.db.backends.__pycache__.base' not found 
15052 INFO: Analyzing hidden import 'django.db.backends.oracle.compiler' 
15052 ERROR: Hidden import 'django.db.backends.oracle.compiler' not found
15052 INFO: Analyzing hidden import 'sqlite3.dump'
15052 INFO: Loading module hook 'hook-sqlite3.py' from '/home/paladin/.dynatrol/venv/lib/python3.11/site-packages/PyInstaller/hooks'...
15147 INFO: Analyzing hidden import 'django.contrib.staticfiles.templatetags'
15147 ERROR: Hidden import 'django.contrib.staticfiles.templatetags' not found
15148 INFO: Analyzing hidden import 'rest_auth.templatetags'
15148 ERROR: Hidden import 'rest_auth.templatetags' not found 
15148 INFO: Analyzing hidden import 'django.contrib.contenttypes.templatetags'
15148 ERROR: Hidden import 'django.contrib.contenttypes.templatetags' not found
15148 INFO: Analyzing hidden import 'django.contrib.staticfiles.context_processors'
15148 ERROR: Hidden import 'django.contrib.staticfiles.context_processors' not found
15148 INFO: Analyzing hidden import 'rest_auth.context_processors'
15148 ERROR: Hidden import 'rest_auth.context_processors' not found
15148 INFO: Analyzing hidden import 'django.contrib.sessions.templatetags' 
15148 ERROR: Hidden import 'django.contrib.sessions.templatetags' not found
15148 INFO: Analyzing hidden import 'django.contrib.sessions.context_processors'
15148 ERROR: Hidden import 'django.contrib.sessions.context_processors' not found
15148 INFO: Analyzing hidden import 'tempus_dominus.templatetags'
15148 ERROR: Hidden import 'tempus_dominus.templatetags' not found 
15148 INFO: Analyzing hidden import 'tempus_dominus.context_processors' 
15148 ERROR: Hidden import 'tempus_dominus.context_processors' not found 
15148 INFO: Analyzing hidden import 'dynatrol.templatetags' 
15149 ERROR: Hidden import 'dynatrol.templatetags' not found 
15149 INFO: Analyzing hidden import 'django.contrib.messages.templatetags' 
15151 ERROR: Hidden import 'django.contrib.messages.templatetags' not found 
15151 INFO: Analyzing hidden import 'rest_framework.context_processors' 
15151 ERROR: Hidden import 'rest_framework.context_processors' not found 
15151 INFO: Analyzing hidden import 'rest_framework.authtoken.templatetags' 
15151 ERROR: Hidden import 'rest_framework.authtoken.templatetags' not found 
15151 INFO: Analyzing hidden import 'multiselectfield.templatetags' 
15157 ERROR: Hidden import 'multiselectfield.templatetags' not found 
15157 INFO: Analyzing hidden import 'multiselectfield.context_processors' 
15157 ERROR: Hidden import 'multiselectfield.context_processors' not found 
15157 INFO: Analyzing hidden import 'django_json_widget.templatetags' 
15158 ERROR: Hidden import 'django_json_widget.templatetags' not found 
15158 INFO: Analyzing hidden import 'django.contrib.admin.context_processors' 
15376 ERROR: Hidden import 'django.contrib.admin.context_processors' not found 
15376 INFO: Analyzing hidden import 'dynatrol.context_processors' 
15376 ERROR: Hidden import 'dynatrol.context_processors' not found 
15376 INFO: Analyzing hidden import 'django.db.backends.postgresql_psycopg2' 
15376 ERROR: Hidden import 'django.db.backends.postgresql_psycopg2' not found 
15376 INFO: Analyzing hidden import 'django.contrib.auth.templatetags' 
15376 ERROR: Hidden import 'django.contrib.auth.templatetags' not found 
15376 INFO: Analyzing hidden import 'rest_framework.authtoken.context_processors' 
15376 ERROR: Hidden import 'rest_framework.authtoken.context_processors' not found 
15376 INFO: Analyzing hidden import 'django.contrib.contenttypes.context_processors' 
15376 ERROR: Hidden import 'django.contrib.contenttypes.context_processors' not found 
15376 INFO: Analyzing hidden import 'django_json_widget.context_processors' 
15376 ERROR: Hidden import 'django_json_widget.context_processors' not found 
15376 INFO: Analyzing hidden import 'mx.DateTime' 
15376 ERROR: Hidden import 'mx.DateTime' not found

bwoodsend

unread,
Feb 28, 2024, 7:10:40 PMFeb 28
to PyInstaller

Please could you tell me what am I doing wrong?

Trying to freeze a web server for one. 🙃

You’re chasing the wrong issue here. Django contains many submodules which can’t be loaded unless you have some strange stuff installed on your machine. PyInstaller collects each submodule only if its loadable which leads to a 18596 WARNING: Hidden import "django.contrib.sessions.templatetags" not found! message for each submodule that isn’t. You appear to has been misled into trying to force PyInstaller to collect those unusable (and unneeded) submodules which has led to the warnings being promoted to errors and has done nothing to fix the real runtime issue which I’m guessing is this one?

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 "django/core/management/__init__.py", line 442, in execute_from_command_line File "django/core/management/__init__.py", line 436, in execute File "django/core/management/base.py", line 413, in run_from_argv File "django/core/management/commands/runserver.py", line 74, in execute File "django/core/management/base.py", line 459, in execute File "django/core/management/commands/runserver.py", line 111, in handle File "django/core/management/commands/runserver.py", line 118, in run File "django/utils/autoreload.py", line 673, in run_with_reloader File "PyInstaller/hooks/rthooks/pyi_rth_django.py", line 24, in _restart_with_reloader File "django/utils/autoreload.py", line 272, in restart_with_reloader File "django/utils/autoreload.py", line 259, in get_child_arguments RuntimeError: Script runserver does not exist. [1326876] Failed to execute script 'manage' due to unhandled exception!

That is caused by django trying to auto reload your code whenever it changes which makes no sense under PyInstaller since the code is frozen and not even visible on the file system. The fix is to pass --noreload.

python -m django startproject hellodjango cd hellodjango/ pyinstaller manage.py ./dist/manage/manage runserver --noreload
​
Reply all
Reply to author
Forward
0 new messages