Pyinstaller and Django Rest


I am trying to use Pyinstaller with django rest, it generates the .exe well but there is an error at the moment of executing the .exe, the error is this

ModuleNotFoundError: No module named 'rest_framework'

my question is how can I install the dependencies using Pyinstaller, or is there another way to do it.


This error ocurrs when you have dynamic imports in your code. In that case, pyinstaller don’t include those packages in exe file. In that case you can:

  1. Add unused import of those packages in your code
  2. Tell pyinstaller to include it

One file option does not change anything in running your code. If you’re create –onefile exe all files created by pyinstaller are packed to exe file, and unpacked to local temp every time when you run exe.

Other Possible Solutions are:

Solution 1:
run your command from parent directory, i.e. instead of

c:\compilation\Gui>pyinstaller --name=gui


c:\compilation>pyinstaller --name=gui Gui\

Also Add runserver to the End of the File.

if still the Issue Persists, Then
Solution 2:
pyinstaller –name=gui –exclude-module=PyQt4 –exclude-module=matplotlib –clean –win-private-assemblies runserver

Answered By – Syed Faizan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published