3

I would like building an executable for a python 3 script that:

  • imports pyqtgraph (with pyqt5)
  • imports theano and pymc3
  • also imports numpy, scipy, sys, os
  • opens a simple GUI made with qt designer and stored in a ‘.ui' file
  • will be distributed on machines with Windows 7+

I tried several tools (py2exe, pyinstaller, pynsist, cx_Freeze) during hours but failed each time. my 'less worse’ result was with pyinstaller (see below) without theano part (and so without a part of the script). Can anyone help me ?

I have 3 files: 2 '.py' files (1 with the main and the other with a bunch of definitions) and a '.ui' describing the GUI. The script makes some statistical analyses, then plots some curves.

Here is an example of my failure with python 3.5 and cx_Freeze (which I think is the most advanced try I had, but I’m not restricted to those tools in particular): I put my 3 files in a directory on a windows machine where everything was painfully installed (with anaconda). I add a file ’setup.py’, which for cx_Freeze is:

from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python 3.5\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python 3.5\tcl\tk8.6'
os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'

setup(
    name = ‘concentrationprofiles',
    version = '0.1',
    description = 'simple tool to simulate concentration profiles. preliminary',
    author = 'SPH',
    options = dict(
        build_exe = dict(
            packages = ['os','sys','numpy','theano','pymc3','pyqtgraph'],#omitting ‘scipy’ ! for some reason when I put ’scipy’ in this list the building fails, but it works without… probably the ‘import scipy’ inside the code is properly interpreted
            includes = ['numpy.core._methods','numpy.lib.format',
                        'pyqtgraph.debug','pyqtgraph.functions',
                        'pyqtgraph.ThreadsafeTimer','cp_util_jul17'],
            include_files = ['GUI_cprofiles_jul17.ui']
        )),
    executables = [Executable(
        script='cprofiles_jul17.py',
        base='Win32GUI',
        targetName=‘concentprofiles.exe'
        )]
    )

I then execute the command line ’python setup.py build’ in the anaconda prompt (equivalent to the command prompt to my knowledge) in the directory with the 4 files. After a lot of episodes and hours of fighting, the building looks fine (100s lines with no error message and going until the end), it creates a ‘build’ directory with a ‘exe.win-amd64-3.5’ subdirectory containing everything needed + the .exe. But when I try and run this .exe I get nothing: no error message, no console or window opening, no fast opening-closing and I can’t find a log… just nothing

I tried to change the ‘base’ option from ‘Win32GUI’ to base=’Console’ and base=None. In these cases I guess there is a fast console-opening-closing that I cannot read since I don’t find the log.

Here are few other bad results during other tries:

  • py2exe: turns out to be incompatible with my usual python 3.6, so I downgraded to 3.5. But even in 3.5, after a few lines it froze: once again no error message, no console or window opening, no fast opening-closing and I can’t find a log… just nothing. not even a ‘build’ directory. Another time I also tried an alternative with python 3.4 but I got an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums. When I eventually got the permission to modify system directories, an instruction ‘regsvr32’ failed (isn’t this for 32 bits only ? but there is no ‘regsvr64’…). I eventually gave up

  • pyinstaller: see updates

  • pynsist: The principle of pynsist is that you don’t get an executable but an installer only. Why not ? I don’t need a .exe as long as I can distribute the code. Unfortunately, after building the installer (with no error) and installing it (again with no visible error), the program gives nothing, like in the cx_Freeze case.

I can add a link to the script files if you want/need.


update august, 18, 2017, 9:20am

Following the suggestion, I opened a new post concerning pyinstaller: build a .exe for Windows from a python 3 script importing theano with pyinstaller.

I invite you to answer the pyinstaller concerns there. This question will be marked as answered if my problem is solved with py2exe or cx_freeze.


update september, 2, 2pm:

I eventually managed to build a .exe with pyinstaller after many episodes.

Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?

Stéphane
  • 1,389
  • 3
  • 13
  • 34
  • I suggest to stick to one question per post, other its hard to mark it as answered. So for this post let the question be that you have created an executable with cx_freeze or py2exe, which does nothing after you start it. I strongly recommend to include the `py2exe` and `cx_freeze` tags so that the experts on those topics see your questions. Remove the `executable` and `python-3.x` tags, they don't add much. Also I doubt that it is related to `pyqtgraph`, which is a pure-python lib. Better ask the pyinstaller/pyqtgraph question in a separate post and include the error messages and proper tags. – titusjan Aug 17 '17 at 14:41
  • ok, I will do that, thank you – Stéphane Aug 18 '17 at 06:57
  • py2exe -- only seems to be compatible with Python 3.3 or earlier -- although I stumbled across a recent python 3.6/3.7 port that is still in beta – Dennis Jensen Aug 11 '20 at 14:43

1 Answers1

1

To create an executable file of your Python program, run the following command in CMD.First you need to install pyinstaller, with the following command:

pip install pyinstaller

And then do the following to create one executable file of your Python program, first, Go to your program path, (with cd) where your Python (.py) file is, and then:

pyinstaller -w -F YourPyFile
daReagion
  • 37
  • 5
  • This of course does not work on Windows while trying to compile the combination of Python 3.7 and PyQtGraph and Python-Qt -- as the PyQtGraph breaks the final executable as it does not seem to handle PyQtGraph and I tested this just recently – Dennis Jensen Aug 11 '20 at 14:42