Skip to content

Commit

Permalink
Add PyInstaller packager example (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Sep 5, 2017
1 parent 9c567bf commit f94eaa6
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
build/
dist/
*.log
__pycache__/
*.pyc
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
Table of contents:
* [Introduction](#introduction)
* [Major sponsors](#major-sponsors)
* [Funding request - v60.0 release](#funding-request---v600-release)
* [Funding for v60.0 release](#funding-for-v600-release)
* [Install](#install)
* [Tutorial](#tutorial)
* [Examples](#examples)
* [Support](#support)
* [Support development](#support-development)
* [Thanks](#thanks)
* [Releases](#releases)
* [Other READMEs](#other-readmes)
* [Quick links](#quick-links)


Expand All @@ -23,7 +24,7 @@ projects. The Chromium project focuses mainly on Google Chrome application
development, while CEF focuses on facilitating embedded browser use cases
in third-party applications. Lots of applications use CEF control, there are
more than [100 million CEF instances](http://en.wikipedia.org/wiki/Chromium_Embedded_Framework#Applications_using_CEF)
installed around the world. [Examples of embedding](examples/Examples-README.md)
installed around the world. [Examples of embedding](examples/README-examples.md)
Chrome browser are available for many popular GUI toolkits including:
wxPython, PyGTK, PyQt, PySide, Kivy, Panda3D and PyGame/PyOpenGL.

Expand Down Expand Up @@ -60,7 +61,7 @@ See the [Support development](#support-development) section for a list of
all the individuals and companies supporting CEF Python.


## Funding request - v60.0 release
## Funding for v60.0 release

For those interested in sponsoring a v60.0 release please see
[Issue #370](../../issues/370).
Expand Down Expand Up @@ -88,13 +89,13 @@ See the [Tutorial.md](docs/Tutorial.md) file.

## Examples

See the [Examples-README.md](examples/Examples-README.md) file.
See the [README-examples.md](examples/README-examples.md) file.


## Support

- Ask questions, report problems and issues on the [Forum](https://groups.google.com/group/cefpython)
- Supported examples are listed in the [Examples-README.md](examples/Examples-README.md) file
- Supported examples are listed in the [README.md](examples/README-examples.md) file
- Documentation is in the [docs/](docs) directory:
- [Build instructions](docs/Build-instructions.md)
- [Contributing code](docs/Contributing-code.md)
Expand Down Expand Up @@ -193,6 +194,12 @@ Additional information for v31.2 release:
- API reference is available in revision [169a1b2](../../tree/169a1b20d3cd09879070d41aab28cfa195d2a7d5/docs/api)


## Other READMEs

- [PyInstaller packager](examples/pyinstaller/README-pyinstaller.md)



## Quick links

### Docs
Expand All @@ -203,8 +210,8 @@ Additional information for v31.2 release:
- [Tutorial](docs/Tutorial.md)


### API categories

### API categories

#### Modules

* [cefpython](api/cefpython.md#cefpython) module
Expand Down Expand Up @@ -259,11 +266,12 @@ Additional information for v31.2 release:
* [StringVisitor](api/StringVisitor.md#stringvisitor-interface) interface
* [WebRequestClient](api/WebRequestClient.md#webrequestclient-interface) interface


### API index


### API index

* [Application settings](api/ApplicationSettings.md#application-settings)
* [accept_language_list](api/ApplicationSettings.md#accept_language_list)
* [app_user_model_id](api/ApplicationSettings.md#app_user_model_id)
* [auto_zooming](api/ApplicationSettings.md#auto_zooming)
* [background_color](api/ApplicationSettings.md#background_color)
* [browser_subprocess_path](api/ApplicationSettings.md#browser_subprocess_path)
Expand Down
1 change: 1 addition & 0 deletions api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* [Application settings](ApplicationSettings.md#application-settings)
* [accept_language_list](ApplicationSettings.md#accept_language_list)
* [app_user_model_id](ApplicationSettings.md#app_user_model_id)
* [auto_zooming](ApplicationSettings.md#auto_zooming)
* [background_color](ApplicationSettings.md#background_color)
* [browser_subprocess_path](ApplicationSettings.md#browser_subprocess_path)
Expand Down
2 changes: 1 addition & 1 deletion docs/Examples.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Examples

Examples are available in the examples/ root directory. See
the [Examples-README.md](../examples/Examples-README.md) file.
the [README-examples.md](../examples/README-examples.md) file.
4 changes: 2 additions & 2 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ basics. This tutorial will discuss the three featured examples:
[hello_world.py](../examples/hello_world.py),
[tutorial.py](../examples/tutorial.py)
and [screenshot.py](../examples/screenshot.py). There are many
more examples that you can find in the [Examples-README.md](../examples/Examples-README.md)
more examples that you can find in the [README-examples.md](../examples/README-examples.md)
file, but these examples are out of scope for this tutorial.


Expand Down Expand Up @@ -423,7 +423,7 @@ Frame object also has the same methods.
You can also serve requests directly in CEF using for example
[ResourceHandler](../api/ResourceHandler.md) object. You can find
an example usage of this object in one of examples listed in
the [Examples-README.md](../examples/Examples-README.md) file.
the [README-examples.md](../examples/README-examples.md) file.

On a side note, upstream CEF also supports custom scheme handlers,
however these APIs were not yet exposed to CEF Python.
Expand Down
12 changes: 11 additions & 1 deletion examples/Examples-README.md → examples/README-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ maintained. If there are any issues in examples read top comments
in sources to see whether this is a known issue with available
workarounds.


**Featured**

- [hello_world.py](hello_world.py) - Basic example, doesn't require any
Expand All @@ -35,6 +36,7 @@ workarounds.
discussed in great details in Tutorial in the [Off-screen rendering](../docs/Tutorial.md#off-screen-rendering)
section.


**Embedding using various GUI frameworks**

- [gtk2.py](gtk2.py): example for [PyGTK](http://www.pygtk.org/)
Expand All @@ -49,6 +51,14 @@ workarounds.
- [wxpython.py](wxpython.py): example for [wxPython](https://wxpython.org/)
toolkit


**Build executable using Python packagers**

- [PyInstaller example](pyinstaller/README-pyinstaller.md):
example of packaging app using [PyInstaller](http://www.pyinstaller.org/)
packager


**Unit tests**

There are also available unit tests and its usage of the API can
Expand All @@ -58,7 +68,7 @@ be of some use. See [main_test.py](../unittests/main_test.py).
## More examples

There are even more examples available, some of them are externally
maintained.
maintained.

- Kivy framework:
see [Kivy](https://github.com/cztomczak/cefpython/wiki/Kivy) wiki page.
Expand Down
116 changes: 116 additions & 0 deletions examples/pyinstaller/README-pyinstaller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# PyInstaller example

Table of contents:
* [Package app](#package-app)
* [When it succeeds](#when-it-succeeds)
* [Fatal error](#fatal-error)
* [Debug app](#debug-app)
* [More details](#more-details)


## Package app

This is an example of using [PyInstaller](http://www.pyinstaller.org/)
packager to build executable from one of CEF Python's examples
(wxpython.py). Only Windows platform is currently supported.

To install required packages type:
```
pip install --upgrade pyinstaller pycrypto
```

To package example type:
```
python pyinstaller.py
```


## When it succeeds

If packaging succeeds you should see "dist/cefapp/" directory open
in explorer on Windows. In there you will find "cefapp.exe" executable
that you can launch.

![cefapp directory](screenshots/cefapp_directory.jpg)


## Fatal error

If there is a "Fatal Error!" message box appearing when running app
then see the next section for how to debug app.

![Fatal Error](screenshots/cefapp_fatal_error.jpg)


## Debug app

In case of a fatal error to debug app pass "--debug" flag when
packaging app:

```
python pyinstaller.py --debug
```

After packaging completes on Windows it will open a new CMD window
and run the cefapp.exe inside it. You should see detailed logs
in console like these:

```
[6708] PyInstaller Bootloader 3.x
[6708] LOADER: executable is \examples\pyinstaller\dist\cefapp\cefapp.exe
[6708] LOADER: homepath is \examples\pyinstaller\dist\cefapp
[6708] LOADER: _MEIPASS2 is NULL
[6708] LOADER: archivename is \examples\pyinstaller\dist\cefapp\cefapp.exe
[6708] LOADER: No need to extract files to run; setting extractionpath to homepath
[6708] LOADER: SetDllDirectory(\examples\pyinstaller\dist\cefapp)
[6708] LOADER: Already in the child - running user's code.
[6708] LOADER: Python library: \examples\pyinstaller\dist\cefapp\python27.dll
[6708] LOADER: Loaded functions from Python library.
[6708] LOADER: Manipulating environment (sys.path, sys.prefix)
[6708] LOADER: sys.prefix is C:\github\CEFPYT~2\examples\PYINST~1\dist\cefapp
[6708] LOADER: Setting runtime options
[6708] LOADER: Initializing python
[6708] LOADER: Overriding Python's sys.path
[6708] LOADER: Post-init sys.path is \examples\pyinstaller\dist\cefapp
[6708] LOADER: Setting sys.argv
[6708] LOADER: setting sys._MEIPASS
[6708] LOADER: importing modules from CArchive
[6708] LOADER: extracted pyimod00_crypto_key
[6708] LOADER: callfunction returned...
[6708] LOADER: extracted struct
[6708] LOADER: callfunction returned...
[6708] LOADER: extracted pyimod01_os_path
[6708] LOADER: callfunction returned...
[6708] LOADER: extracted pyimod02_archive
[6708] LOADER: callfunction returned...
[6708] LOADER: extracted pyimod03_importers
[6708] LOADER: callfunction returned...
[6708] LOADER: Installing PYZ archive with Python modules.
[6708] LOADER: PYZ archive: out00-PYZ.pyz
[6708] LOADER: Running pyiboot01_bootstrap.py
[6708] LOADER: Running wxpython.py
Traceback (most recent call last):
File "wxpython.py", line 11, in <module>
File "c:\python27\lib\site-packages\PyInstaller-3.3-py2.7.egg\
PyInstaller\loader\pyimod03_importers.py", line 396,
in load_module exec(bytecode, module.__dict__)
File "site-packages\cefpython3\__init__.py", line 50, in <module>
File "c:\python27\lib\site-packages\PyInstaller-3.3-py2.7.egg\
PyInstaller\loader\pyimod03_importers.py", line 687,
in load_module module = imp.load_module(fullname, fp, filename,
ext_tuple)
File "cefpython_py27.pyx", line 283, in init cefpython_py27
(cefpython_py27.cpp:110881)
ImportError: No module named json
[6708] Failed to execute script wxpython
[6708] LOADER: OK.
[6708] LOADER: Cleaning up Python interpreter.
```


## More details

The corresponding issue in the tracker is [Issue #135](https://github.com/cztomczak/cefpython/issues/135).

See also the [Build executable](https://github.com/cztomczak/cefpython/blob/master/docs/Tutorial.md#build-executable)
section in Tutorial.
Loading

1 comment on commit f94eaa6

@846948768
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried many times and found that using pyinstaller 3.4 may cause problem and failed to build exe, while using pyinstaller 3.3 will be OK.

Please sign in to comment.