pyinstaller / pyinstaller/pyinstaller

Crash if Django `settings.py` has Syntax Error

Open
#2,473 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:hooks pull-request wanted
Dominant language
Python
Stars
13.1k
Forks
2k
Avg merge
1d 3h
Merged PRs (30d)
11

Description

I have stuck with the below error

$ pyinstaller --onefile --name=myapp ../myapp/manage.py
171 INFO: PyInstaller: 3.2.1
172 INFO: Python: 2.7.13
172 INFO: Platform: Windows-7-6.1.7601-SP1
174 INFO: wrote C:\MAMP\htdocs\installer\myapp.spec
174 INFO: UPX is not available.
176 INFO: Extending PYTHONPATH with paths
['C:\MAMP\htdocs\myapp', 'C:\MAMP\htdocs\installer']
177 INFO: checking Analysis
177 INFO: Building Analysis because out00-Analysis.toc is non existent
177 INFO: Initializing module dependency graph...
180 INFO: Initializing module graph hooks...
269 INFO: running Analysis out00-Analysis.toc
274 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by c:\python27\python.exe
394 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
397 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_accf10dbe1dc8ba2.manifest
399 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
400 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_acd388d7e1d8689f.manifest
544 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_none ...
544 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251.manifest
546 INFO: Searching for file msvcr90.dll
547 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251\msvcr90.dll
547 INFO: Searching for file msvcp90.dll
547 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251\msvcp90.dll
547 INFO: Searching for file msvcm90.dll
548 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251\msvcm90.dll
700 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
700 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_accf10dbe1dc8ba2.manifest
703 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
703 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_acd388d7e1d8689f.manifest
703 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 6161)
841 INFO: Caching module hooks...
848 INFO: Analyzing C:\MAMP\htdocs\myapp\manage.py
7759 INFO: Processing pre-find module path hook distutils
8473 INFO: Loading module hooks...
8473 INFO: Loading module hook "hook-distutils.py"...
8473 INFO: Loading module hook "hook-django.core.management.py"...
9409 INFO: Processing pre-safe import module hook xmlplus
10615 INFO: Excluding import 'IPython'
10617 WARNING: Removing import django.core.management.commands.shell from module IPython
10618 INFO: Import to be excluded not found: 'Tkinter'
10618 INFO: Import to be excluded not found: 'matplotlib'
10618 INFO: Loading module hook "hook-xml.py"...
10620 INFO: Loading module hook "hook-django.db.backends.py"...
11518 INFO: Loading module hook "hook-httplib.py"...
11519 INFO: Loading module hook "hook-django.db.backends.oracle.base.py"...
11523 INFO: Loading module hook "hook-xml.dom.domreg.py"...
11524 INFO: Loading module hook "hook-django.db.backends.mysql.base.py"...
11526 INFO: Loading module hook "hook-django.core.mail.py"...
11617 INFO: Loading module hook "hook-django.template.loaders.py"...
11993 INFO: Loading module hook "hook-encodings.py"...
12740 INFO: Loading module hook "hook-sqlite3.py"...
12878 INFO: Loading module hook "hook-django.py"...
12880 INFO: Django root directory C:\MAMP\htdocs\myapp\myapp
Traceback (most recent call last):
File "C:\Python27\Scripts\pyinstaller-script.py", line 11, in
load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
File "c:\python27\lib\site-packages\PyInstaller_main
.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\python27\lib\site-packages\PyInstaller_main_.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line 734, in build
exec(text, spec_namespace)
File "", line 16, in
File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line 212, in init
self.postinit()
File "c:\python27\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in postinit
self.assemble()
File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line 470, in assemble
module_hook.post_graph()
File "c:\python27\lib\site-packages\PyInstaller\building\imphook.py", line 409, in post_graph
self._load_hook_module()
File "c:\python27\lib\site-packages\PyInstaller\building\imphook.py", line 376, in load_hook_module
self.hook_module_name, self.hook_filename)
File "c:\python27\lib\site-packages\PyInstaller\hooks\hook-django.py", line 31, in
settings_py_imports = django_dottedstring_imports(root_dir)
File "c:\python27\lib\site-packages\PyInstaller\utils\hooks\django.py", line 32, in django_dottedstring_imports
ret = eval_script('django_import_finder.py', env=env)
File "c:\python27\lib\site-packages\PyInstaller\utils\hooks_init
.py", line 127, in eval_script
return eval(txt)
File "", line 1
C:\MAMP\htdocs\myapp\media
^
SyntaxError: invalid syntax

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported pyinstaller command with a Django project whose settings.py has a syntax error. Start with hooks/hook-django.py and utils/hooks/django.py, then follow the django_import_finder.py evaluation path shown in the traceback. Done means the failure is handled with an actionable result rather than the current crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.