You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-34Lines changed: 70 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This post shows how to use Electron as the GUI component of Python applications.
6
6
7
7
## important notice
8
8
9
-
The following are copied from my [original post](https://www.fyears.org/2017/02/electron-as-gui-of-python-apps-updated.html). They should be the same.
9
+
The following are copied from my [original post](https://www.fyears.org/2017/02/electron-as-gui-of-python-apps-updated.html). They should be the same.**If there are inconsistency, the `README.md` on the GitHub repo is more accurate.**
10
10
11
11
## original post and debates
12
12
@@ -125,16 +125,13 @@ And the `index.html`, `main.js`, `package.json` and `renderer.js` are modified f
125
125
126
126
First of all, since we already have the Python application running, the Python environment should be fine. I strongly recommend developing Python applications in `virtualenv`.
127
127
128
-
Try install `zerorpc`, and `pyinstaller` (for packaging).
128
+
Try install `zerorpc`, and `pyinstaller` (for packaging). On Linux / Ubuntu we may need to run `sudo apt-get install libzmq3-dev`**before**`pip install`.
129
129
130
130
```bash
131
131
pip install zerorpc
132
132
pip install pyinstaller
133
-
```
134
-
135
-
If working on Windows, also
136
133
137
-
```bash
134
+
# for windows only
138
135
pip install pypiwin32 # for pyinstaller
139
136
```
140
137
@@ -154,7 +151,7 @@ We need to configure the `package.json`, especially the `main` entry:
154
151
"start": "electron ."
155
152
},
156
153
"dependencies": {
157
-
"zerorpc": "*"
154
+
"zerorpc": "fyears/zerorpc-node"
158
155
},
159
156
"devDependencies": {
160
157
"electron": "^1.4.1",
@@ -163,53 +160,83 @@ We need to configure the `package.json`, especially the `main` entry:
163
160
}
164
161
```
165
162
166
-
Ironically, to compile Node.js C/C++ native codes, we need to have `python2` configured, no matter what Python version we are using for our Python application. Check out the [official guide](https://github.com/nodejs/node-gyp).
163
+
Clean the caches:
167
164
168
-
If working on Windows, open PowerShell **as Administrator**, and run
# It's very important to set the electron version correctly!!!
186
+
# check out the version value in your package.json
187
+
npm install --runtime=electron --target=1.4.15
188
+
189
+
# verify the electron binary and its version by opening it
190
+
./node_modules/.bin/electron
172
191
```
173
192
174
-
The above command installs Python 2.7 in `%USERPROFILE%\.windows-build-tools\python27` and other VS libraries. Everything should be set and should not cause any conflict with the previously-installed Python environment.
193
+
The `npm install` will install `zerorpc-node` from [my fork](https://github.com/0rpc/zerorpc-node/pull/84) to skip building from sources.
175
194
176
-
Also download VC 2010 runtime from [here](https://www.microsoft.com/en-us/download/details.aspx?id=14632) due to a [bug](https://github.com/JustinTulloss/zeromq.node/issues/582).
195
+
All libraries should be fine now.
177
196
178
-
Then set the `npm`[for Electron](https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md), and install the required libraries.
197
+
#### optional: building from sources
179
198
180
-
On Linux / OS X:
199
+
If the above installation causes any errors **even while setting the electron version correctly**, we may have to build the packages from sources.
200
+
201
+
Ironically, to compile Node.js C/C++ native codes, we need to have `python2` configured, no matter what Python version we are using for our Python application. Check out the [official guide](https://github.com/nodejs/node-gyp).
202
+
203
+
Especially, if working on Windows, open PowerShell **as Administrator**, and run `npm install --global --production windows-build-tools` to install a separated Python 2.7 in `%USERPROFILE%\.windows-build-tools\python27` and other required VS libraries. We only need to do it at once.
204
+
205
+
Then, **clean `~/.node-gyp` and `./node_modules` caches as described above at first.**
206
+
207
+
Set the `npm`[for Electron](https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md), and install the required libraries.
208
+
209
+
Set the environment variables for Linux (Ubuntu) / OS X / Windows:
181
210
182
211
```bash
212
+
# On Linux / OS X:
213
+
183
214
# env
184
215
export npm_config_target=1.4.15 # electron version
On Windows PowerShell, set environement variables in [different way](http://stackoverflow.com/questions/714877/setting-windows-powershell-path-variable):
224
+
npm config ls
225
+
```
199
226
200
227
```powershell
228
+
# On Window PowerShell (not cmd.exe!!!)
229
+
201
230
$env:npm_config_target="1.4.15" # electron version
Uninstall everything, **set up the npm environment variables correctly especially for the electron version**, remember to `activate` the virtualenv if using Python `virtualenv`.
562
+
527
563
### further optimization?
528
564
529
565
Trim some unnecessary files in Python executable by configuring `pyinstaller` further. Trim Electron (is it possible?). Use even faster IPC methods (though `ZeroMQ` is one of the fastest in most cases).
0 commit comments