This is my directory structure where renderer.js
is included by index.html
.
The python scripts visitor.py
and download.py
/Application/test.app/Contents/Resources/app.asar/remderer.js:226 Error: python: can't open file 'visitor.py': [Error 2] No such file or directory
is remderer.js, but other place is renderer.js, so please makesure is NOT your typo. If is, correct it.
Actually electron-builder
IS bundled your python file, but due to asar
, your python-shell
can NOT find your python file, so cause the error.
Easiest but not recommend by official: disable asar
disable asar
change you package.json
to:
{
...
"build": {
"appId": "com.example.app",
...
"asar": false,
then in your renderer.js
, which contain python-shell
code, maybe like this:
import {PythonShell} from 'python-shell';
PythonShell.run('visitor.py', null, function (err) {
if (err) throw err;
console.log('finished');
});
should working now.
after disable asar, the all related file path is not contain asar, become this:
/Application/test.app/Contents/Resources/app/visitor.py
/Application/test.app/Contents/Resources/app/renderer.js
that is, .app
file structure is:
|_ test.app
|_ Contents
|_ Resources
|_ app
|_ styles.css
|_ main.js
|_ package.json
|_ dist/
|_ node_modules/
|_ renderer.js
|_ visitor.py
|_ download.py
...
keep enable asar, put extra files into unpack
:
change you package.json
to:
{
...
"build": {
"appId": "com.example.app",
...
"asar": true,
"asarUnpack": [
"visitor.py",
"download.py"
"renderer.js"
],
the packaged .app
file structure is:
|_ test.app
|_ Contents
|_ Resources
|_ app.asar # a single compressed binary file
|_ app.asar.unpacked # a folder/directory, contain unpacked origin files
|_ visitor.py
|_ download.py
|_ renderer.js
your renderer.js
, maybe NOT need change, and should working.
more details about asarUnpack
please refer official doc: Overridable per Platform Options
PS: some other asar and related trying, can refer my Chinese post: 【已解决】mac中PyInstaller打包后的二进制文件在electron-builder打包后app中有些无法通过child_process的execFile运行
You need to specify them as follows:
"extraFiles": [
"from":"source path",
"to":"your destination"
]
if you want to put those files by creating directory then use extraResources
"extraResources": [
"from":"source path",
"to":"some directory name"
]
for more info refer here