3

I am using cefpython to create a simple HTML5 based app. I am using Python and pywin32 to draw a simple window and render the frame there.

I want to compile my .py into an .exe but I have no idea how to do it. I tried using py2exe but when I run the result I get an error

Traceback (most recent call last):
  File "myApp.py", line 19, in <module>
  File "cefpython1\__init__.pyc", line 4, in <module>
ImportError: cannot import name cefpython_py27

I tried copying cefpython_py27.pyd in the distribution directory but seemed to have no effect.

Can anyone help me? Is this do-able at all?

Thanks.

Andrei Nemes
  • 3,062
  • 1
  • 16
  • 22

4 Answers4

4

i messed around with it finaly i managed with following steps (i use python2.7): i imported cefpython like so:

from cefpython1 import cefpython_py27 as cefpython

my py2exe complained about python32.dll not found, since im lazy and cba to mess with __ini__ file and search where its imported i just added python32.dll to dll_excludes in options in setup file. After py2exe finished i also had to manualy copy these foler and file to my dist folder:

- C:\Python27(your python path)\Lib\site-packages\cefpython1\locales - whole folder
- C:\Python27(your python path)\Lib\site-packages\cefpython1\icudt.dll

be warned tho dlls are relatively big: icudt.dll = 9.8MB, libcef.dll = 24.3MB so dont expect small dist folder size.

hidetr
  • 56
  • 1
  • This was helpful but now I get wx.version=2.8.12.1 (msw-unicode) [0808/130201:ERROR:child_process_launcher.cc(326)] Failed to launch child process – Sid Kshatriya Aug 08 '13 at 07:40
  • The above problem can be solved by copying subprocess.exe (Thanks to Czarek the cefpython creator for this tip). Make sure other files from the cefpython3 folder e.g. cef.pak etc., ffmpegsumo.dll etc. are copied too. – Sid Kshatriya Aug 08 '13 at 07:59
4

Extending the answer of hidetr, adding something like this to setup.py will copy the needed files:

def get_cefpython_path():
    import cefpython1 as cefpython

    path = os.path.dirname(cefpython.__file__)
    return "%s%s" % (path, os.sep)

def get_data_files():
    cefp = get_cefpython_path()
    data_files = [('', ['%s/icudt.dll' % cefp,
          '%s/d3dcompiler_43.dll' % cefp,
          '%s/d3dx9_43.dll' % cefp,
          '%s/devtools_resources.pak' % cefp,
          '%s/ffmpegsumo.dll' % cefp,
          '%s/libEGL.dll' % cefp,
          '%s/libGLESv2.dll' % cefp,
          '%s/Microsoft.VC90.CRT.manifest' % cefp,
          '%s/msvcm90.dll' % cefp,
          '%s/msvcp90.dll' % cefp,
          '%s/msvcr90.dll' % cefp]),
        ('locales', ['%s/locales/en-US.pak' % cefp]),
        ]
    return data_files

setup(
    data_file = get_data_files()
    ...
Madis
  • 411
  • 5
  • 7
4

Here is what worked for me with Python 2.7 Win32. I've used the cefsimple.py example from the cefpython's example folder for demonstration. You need win32gui module for this example to work so install this first.

  • Downloaded and installed the cefpython1 pacakage.
  • Copied cefsimple.html, cefsimple.py, cefwindow.py and icon.ico from cefpython's example directory into a separate directory and altered cefsimple.py to simply import cefpython as from cefpython1 import cefpython. The __file__ based module detection is not working inside py2exe and causes errors so I've removed it (maybe there's a better way around).
  • Created the following setup.py in the folder containing the above files copied:

    from setuptools import setup
    import py2exe
    import os

    def get_cefpython_path():
        import cefpython1 as cefpython

        path = os.path.dirname(cefpython.__file__)
        return "%s%s" % (path, os.sep)

    def get_data_files():
        cefp = get_cefpython_path()
        data_files = [('', [
              '%s/icudt.dll' % cefp,
              '%s/d3dcompiler_43.dll' % cefp,
              '%s/d3dx9_43.dll' % cefp,
              '%s/devtools_resources.pak' % cefp,
              '%s/ffmpegsumo.dll' % cefp,
              '%s/libEGL.dll' % cefp,
              '%s/libGLESv2.dll' % cefp,
              '%s/Microsoft.VC90.CRT.manifest' % cefp,
              '%s/msvcm90.dll' % cefp,
              '%s/msvcp90.dll' % cefp,
              '%s/msvcr90.dll' % cefp,
              'icon.ico', 'cefsimple.html']),
            ('locales', ['%s/locales/en-US.pak' % cefp]),
            ]
        return data_files

    setup(
        data_files = get_data_files(),
        windows=['cefsimple.py'],
        options={
            "py2exe": {
                "includes": ["json", "urllib"]
            }
        }
    )
  • Then just simply run py2exe as follows in the directory: python setup.py py2exe
  • You can now run the generated application with dist/cefsimple.exe

You can get the files for this example from my Google Drive.

NagyI
  • 5,907
  • 8
  • 55
  • 83
2

There is now an official example for creating executable using PyInstaller. Currently as of this writing only Windows platform is supported. See:

https://github.com/cztomczak/cefpython/blob/master/examples/pyinstaller/README-pyinstaller.md

enter image description here

Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56