From cf7d04099ec4370a4e6e33f98a4ed77061a80882 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Tue, 24 Jun 2014 17:23:10 -0400 Subject: [PATCH] made pyinstaller work for windows (#35) --- BUILD.md | 9 ++++----- onionshare_gui/webapp.py | 12 +----------- setup/onionshare-launcher.py | 7 ++++++- setup/onionshare-win.spec | 24 ++++++++++++++++++++++++ setup/onionshare.ico | Bin 0 -> 12862 bytes 5 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 setup/onionshare-win.spec create mode 100644 setup/onionshare.ico diff --git a/BUILD.md b/BUILD.md index 26565cff..ecd1f957 100644 --- a/BUILD.md +++ b/BUILD.md @@ -69,14 +69,13 @@ The first time you're setting up your dev environment: * Right click on Computer, go to Properties. Click "Advanced system settings". Click Environment Variables. Under "System variables" double-click on Path to edit it. Add `;C:\Python27;C:\Python27\Scripts` to the end. Now you can just type `python` to run python scripts in the command prompt. * Go to https://pip.pypa.io/en/latest/installing.html. Right-click on `get-pip.py` and Save Link As, and save it to your home folder. * Open `cmd.exe` as an administrator. Type: `python get-pip.py`. Now you can use `pip` to install packages. +* Open a command prompt and type: `pip install flask stem pyinstaller` * Go to http://www.riverbankcomputing.com/software/pyqt/download and download the latest PyQt4 for Windows for python 2.7, 32-bit (I downloaded `PyQt4-4.11-gpl-Py2.7-Qt4.8.6-x32.exe`), then install it. -* Go to http://www.py2exe.org/ and download the latest py2exe for python 2.7, 32-bit (I downloaded `py2exe-0.6.9.win32-py2.7.exe`), then install it. -* Open a command prompt and type: `pip install flask stem` -* Go to `C:\Python27\Lib\site-packages\flask\` and delete the folder `testsuite`. This is necessary to work around a py2exe bug. +* Go to http://sourceforge.net/projects/pywin32/ and download and install the latest 32-bit pywin32 binary for python 2.7. I downloaded `pywin32-219.win32-py2.7.exe`. -To make an exe: +To make a .exe: -* Open a command prompt, cd to the onionshare folder, and type: `python setup.py py2exe`. This will create a ton of files in `dist`, including `onionshare.exe`. +* Open a command prompt, cd into the onionshare directory, and type: `pyinstaller -y setup\onionshare-win.spec`. Inside the `dist` folder there will be a folder called `onionshare` with `onionshare.exe` in it. ## Tests diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index db4bcc52..80f2c3f8 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -26,17 +26,7 @@ import logging log_handler = logging.FileHandler('{0}/onionshare.web.log'.format(temp_dir)) log_handler.setLevel(logging.WARNING) -template_folder = './templates' -if platform.system() == 'Windows': - # pyinstaller sets sys.frozen=1 on run - application_path = "" - if getattr(sys, "frozen", False): - application_path = os.path.dirname(sys.executable) - elif __file__: - application_path = os.path.dirname(__file__) - template_path = os.path.join(application_path, "templates") - -app = Flask(__name__, template_folder=template_path) +app = Flask(__name__, template_folder='./templates') app.logger.addHandler(log_handler) @app.route("/") diff --git a/setup/onionshare-launcher.py b/setup/onionshare-launcher.py index f0b9b7c0..e8b4c0f5 100644 --- a/setup/onionshare-launcher.py +++ b/setup/onionshare-launcher.py @@ -1,2 +1,7 @@ -import onionshare_gui +# import stuff for pyinstaller to find +import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, random, functools +import PyQt4.QtCore, PyQt4.QtGui, PyQt4.QtWebKit +import stem, stem.control, flask +import onionshare, onionshare_gui + onionshare_gui.main() diff --git a/setup/onionshare-win.spec b/setup/onionshare-win.spec new file mode 100644 index 00000000..b4debd5a --- /dev/null +++ b/setup/onionshare-win.spec @@ -0,0 +1,24 @@ +# -*- mode: python -*- +a = Analysis(['setup/onionshare-launcher.py'], + hiddenimports=['onionshare', 'onionshare_gui'], + hookspath=None, + runtime_hooks=None) +pyz = PYZ(a.pure) +exe = EXE(pyz, + a.scripts, + exclude_binaries=True, + name='onionshare.exe', + debug=False, + strip=False, + upx=True, + icon='setup/onionshare.ico', + console=False ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + Tree('onionshare', prefix='onionshare'), + Tree('onionshare_gui', prefix='onionshare_gui'), + strip=False, + upx=True, + name='onionshare') diff --git a/setup/onionshare.ico b/setup/onionshare.ico new file mode 100644 index 0000000000000000000000000000000000000000..ee2d0f63c70f4d5ef5677100b10bbf6a4535b071 GIT binary patch literal 12862 zcmd6uTWD2B6oz-SHr}Nz6x%)seQ1?Z1mC>HL`^U`xil#?S`mzlnYH$go|nbH++2_Eh2G+2p7*xrd5ig_%WLM>@1O9W(s`vyCXKW|B4NVeg$Wec z5Tp&;U=&@taOs?+hJhi&+erecio=dqliT~D(o1-@Y}f< zUF)qq_w~7FPoAX*&xH%&s6bI9n50%%xR@3sk3JuDfsqLfDlVS7SonIO1&je6O4Sp_ zLRjM2Nu7Byd9ZJ=<+B#{Rm6!Vu+`7p9Q^$!3cJQ3+9FFdX)YHdL@BMbKc6DuzmxI?fyyoWyMKg=m zdF$xO_wuiNcje)Ohht;r_B+%!)KuQ&hfTbcX8tSRsnns`y`WR-Z59#dyM5kd^mga% zrcau3y<7kTK#u`}S>0kn#hVouPF#3A_*fWw{^)5gZhE!=8w|>4=pI)(>uv1T+W)HeCfdi!lu5Uet2M5mu$2dJz0HHH^J@&3RP-7LrCy;rMI$d zUYUSNqfwAmaP0GA!LSMHVlA*bWRJD$Vke?DK5q8vt z?R(lyv1U&3%6KsQ?WpZ2nEs+tqrvSf4CCWL7K6aJ1roq?oR&7mVzM$n&&xZq`G_Gc zc*~SBu`**!IMc3F(7+vS)oqV@9|ajBdk6zkM?yjbT95~aNb|^4?OF(CLfRsqAtr>B z$u1{2$^v8=G8+OcrA2{W_6m~ipk%#=%>*(Fex;rLgbhliPda;8o2`!xFm3QC1rn)s zn0)DHGiOVeDY7*10>=c0h46+o0MF6G0c4RDIYj0_y%45C`Z-KFQZ3TN=}ZV~fx|lT zKD@!U$VXGgR1mQplVAB*yyB;at|JW2^bYf6mgVt$Yfut$*EEMJVP8M zqHSO$#5Lm1r*@lslhpH_p+F&OS5G=>KdI}UYiXOvcVpV{F zfyW&@^w8Cfj*Q;<2-hG6)g#~?y}swOBySRlqn{N>(Is^wb&OZ6LdN`kxI38Bmo zcF@cTLFFhUs6F!@R4XBl7}6jU`I)1Ql#m8I3rnQBi6Q`lh_c{GX-F3+?a6M4At^yM zh!sc?l?G;ti~a@i3S-Rkn*2tW=VklXX8z-VfAxiO8TGGg#>b!f*F|x%IAN!MKRr$! zXYg-fK$`#4l(@#(5fEobK;qi3=oWOTYj)z=sqUwTU7OW-R@7CIrT-lzKQZ2^RD|N~ zQsdc)Yr^itJS47(c}mP%;u?2@?}%n!5RU2eugrUwf5l;O0r(~1r-a|cj}XTFio~XI J|0nMEe*x-{c#{AC literal 0 HcmV?d00001