環境 | Electron + Python + Vue

d.l.spm
4 min readJun 3, 2020

採坑筆記

Python

  • 其他
  • zerorpc

Node.js | Electron

  • package.json(node_modules)

Python 2.x 3.x 共存

Python

其他

  • pythoncom
  • COMError

pythoncom

問題:ImportError: No module named pythoncom
原因:pywin32

pip install pywin32

COMError

問題:from comtypes import COMError;ModuleNotFoundError: No module named ‘comtypes’
原因: comtypes

pip install comtypes

comtypes.gen.SKCOMLib as sk

問題:ModuleNotFoundError: No module named ‘comtypes.gen.SKCOMLib’

第一、原因:python 版本問題(3.8 不能)

第二、註冊問題(SKCOM.dll 要和主程式同目錄)

import comtypes.client 
comtypes.client.GetModule(os.path.split(os.path.realpath(__file__))[0] + r'\SKCOM.dll')

npm install

錯誤:“WARN deprecated request@2.88.2: request has been deprecated”

原因:資源問題,沒有配置淘寶鏡像

cannot find prebuild-install

npm i prebuild-install

zerorpc

輕量級分散式系統

RPC(Remote Procedure Call Protocol) — — 遠端過程呼叫協議,它是一種通過網路從遠端計算機程式上請求服務,而不需要了解底層網路技術的協議”,基於 TCP 的通訊協議

設計初衷
『simple tool to solve a simple problem』

pip install zerorpc

錯誤:“WARN deprecated request@2.88.2: request has been deprecated”
原因:資源問題,沒有配置淘寶鏡像

npm config set registry https://registry.npm.taobao.org#驗證
npm config get registry
npm install -g @vue/cli

錯誤:cannot find prebuild-install

https://www.npmjs.com/package/prebuild-install
npm i prebuild-install

zeromq

npm i zmq-windows-prebuilt

node-gyp — Node.js native addon build tool

第一步:node-gyp

npm install -g node-gyp

第二步:windows-build-tools

問題: spawnSync powershell.exe ENOENT
解決:%SystemRoot%/system32/WindowsPowerShell/v1.0(沒用)

  • 開始->搜尋 PowerShell -> Windows PowerShell(開啟超級管理員)->再輸入指令
  • 切記會載非常久所以要有耐心
npm install --global windows-build-tools
npm install --global --production windows-build-tools@4.0.0

在 try 有用下面的 Installing as a Non-Administrator

1. 以管理員身分執行 cmd.exe
2. 輸入指令
set APPDATA=C:\Users\<Me>\AppData\Roaming
npm config set prefix C:\Users\<Me>\AppData\Roaming\npm
set USERNAME=<Me>
set USERPROFILE=C:\Users\<Me>
3. Run npm install -g windows-build-tools

錯誤:could not install visual studio build tools npm
解決: (環境變數 python27 在前面)

1. Remove C:\Users\<user>\.windows-build-tools
2. npm uninstall — global windows-build-tools
3. npm i -g windows-build-tools

太感動

not looking for VS2013 as it is only supported up to Node.js 8
更新 Visual C++ build tools

npm config set msvs_version 2015

補充 : zerorpc.Client()

zerorpc.exceptions.TimeoutExpired: timeout after 30s

解決辦法更改 zerorpc 設定timeout = 30 的地方 (上方紅色框的部分,依照自己的檔案位置去找尋)

我這邊只有在 core.py 有找到 timeout = 30
# timeout=30 更改
timeout=60 * 60 * 24 * 30 * 12

第三步:下載 Visual Studio (一定要有 C++)

npm install --msvs_version=xxxx
npm config set msvs_version 2017
npm i zerorpc
git 問題
git -v

官網載點

配置路徑(git-core, bin)

1. C:\Program Files\Git\mingw64\libexec\git-core
2. C:\Program Files\Git\bin

git -v

重裝 zeromq(環境變數 python27 在前面)

npm uninstall zeromq -g 
npm uninstall zmq -g
npm install — save zeromq

Node.js | Electron

Node 官網載點

詳細安裝流程

Electron

electron-builder特點:

  1. 利用electron-builder 可以打包成msi 、exe、dmg文件,macOS系统,只能打包dmg文件,window系统才能打包exe,msi文件
  2. 此套件支持平台有:Windows (32/64 bit)、OS X ( macOS)、Linux (x86/x86_64)
  3. 可以将prepackage目錄(手動或使用electron-packager生成的目錄)打包成安裝檔
  4. 支持Auto Update

5. 支持CLI和JS API兩種使用方式

TypeError: can not serialize ‘generator’ object

--

--