0

I need to run python scripts from my Electron app. I have to set up a python virtual env post installation. Something like the following (but hopefully platform agnostic).

cd /Applications/z.app/Contents/Resources/app.asar.unpacked
brew reinstall python
brew upgrade python
pip3 install --upgrade pip
pip3 install virtualenv
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
  • What have you tried so far? Please show your work. – Soviut Jul 13 '18 at 08:35
  • Also, when you say "post installation" do you mean each time your app runs, or once after the installer is finished. If it's the latter, couldn't you just put a post-install task in your installer bundle? This would be totally unrelated to Electron. – Soviut Jul 13 '18 at 08:37
  • I have done what's mentioned here https://stackoverflow.com/a/41209644/865220, Now I can trigger python script from electron app inside `/Applications/z.app/Contents/Resources/app.asar.unpacked/` but there is neither guarantee of python nor python modules with appropriate version to be present there, that's why I am looking to setup `virtualenv` there post installation. If you can even suggest other means like deploying docker, vagrant etc I am okay to adopt those as well – ishandutta2007 Jul 13 '18 at 10:16
  • only once and that should happen before user tries to open the app for the first time. sorry for inconvenience I ignored these details thinking that mentioning setting up python environment on client makes these obvious. – ishandutta2007 Jul 13 '18 at 17:53

1 Answers1

0

Step one:

The approach I took is to create a a python native app using py2app alongside an electron app But in that too faced few issues as I was using anaconda. Following this helped https://github.com/stuarteberg/helloworld

Step two:

2(a)

You will encounter pyqt not found error

ImportError: No module named PyQt4.QtGui

then do

  1. conda install pyqt=4
  2. Restart terminal

2(b)(optional)

Above repo is in pyqt4, If you need pyqt5:

To install pyqt5 on Mac first install macports(https://guide.macports.org/#installing.macports), then do

unset PYTHONPATH
brew install sip --with-python3
brew install pyqt --with-python3
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129