Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a standalone version for Windows #15

Closed
CamiloMM opened this issue Jan 9, 2013 · 22 comments
Closed

Create a standalone version for Windows #15

CamiloMM opened this issue Jan 9, 2013 · 22 comments

Comments

@CamiloMM
Copy link

CamiloMM commented Jan 9, 2013

First off, since I'm not a Python developer I have no idea if this is easy to include in a build process or not. However, since I've seen several Python applications that run on Windows without having to install Python (for example, PyLoad), I think that it might be easier in Python than say, .NET or Java.

I'm not expecting this issue to be fixed soon - I just thought I should post it as a wish.

Also, it doesn't necessarily need an installer (I think any user of this knows how to copy a folder to Program Files), but with one, it would be possible to add howdoi to the %PATH%, so that people can pop up a prompt and run it easily.

@CamiloMM
Copy link
Author

By the way... the CHANGES.txt mentions "Added Windows executable". What does that mean? I can't find it.

@gleitz
Copy link
Owner

gleitz commented Jan 11, 2013

Yes I tried adding a windows executable but the existence of the file on PyPI broke the pip installs for linux users so I removed it.

@CamiloMM
Copy link
Author

Hi @gleitz, could you please tell me how did you make such an executable? I want to make one for a friend. Or if you have time, host it here on GitHub (either the executable or a guide), it would be of benefit to people.

@gleitz
Copy link
Owner

gleitz commented Jan 11, 2013

I believe you would want to use http://www.py2exe.org/

@CamiloMM
Copy link
Author

Any specific directions? I had less than success with PyInstaller so I'm asking if you had any pitfall with py2exe or it went just right in the first try.

@gleitz
Copy link
Owner

gleitz commented Jan 11, 2013

Not sure. Previously I created the exe through the pypi upload process but it didn't work. Let me know if you have better success!

@CamiloMM
Copy link
Author

I followed the tutorial of py2exe, by adding an import directive to setup.py and running python setup.py py2exe and seemingly it worked but there isn't any howdoi.exe like it thought there would be. The files under ./dist are:

10/04/2012  23:31            59.904 bz2.pyd
11/01/2013  21:08         1.582.231 library.zip
10/04/2012  23:31         2.303.488 python27.dll
10/04/2012  23:31             9.728 select.pyd
10/04/2012  23:31           686.592 unicodedata.pyd
10/04/2012  23:31            49.664 w9xpopen.exe
10/04/2012  23:31           285.184 _hashlib.pyd

(and library.zip only contains python files)

@gleitz
Copy link
Owner

gleitz commented Jan 12, 2013

Sorry, I don't have a windows machine so I can't test it.

@CamiloMM
Copy link
Author

@gleitz Luckily, I'm making progress. I had to edit the setup.py script though. I'll post here as soon as I have a working binary.

@CamiloMM
Copy link
Author

Ok, this took me more time than I'm willing to admit so I don't even know everything I did in detail.
I had to edit setup.py, I think it boils down to:

from setuptools import setup, find_packages
import py2exe // <-- this line
import howdoi
import os

// and the following changes to that `setup()` call parameters:

      console=['howdoi/howdoi.py'],
      options={
        'py2exe': 
        {
            'includes': ['lxml._elementpath', 'gzip'],
        }
      },
      #entry_points={
      #  'console_scripts': [
      #      'howdoi = howdoi.howdoi:command_line_runner',
      #      ]
      #  },

And I think I installed a package or two, but not sure if necessary. Then I had a folder with an exe that I could run. Great! Now, I started removing the files until it broke and placing them back (actually, just renaming) to strip down everything possible. This shaved a lot of size.

Then, I used 7-zip to create a self-extracting exe that takes out that mess and runs it.

The result is a howdoi.exe that's completely self-contained in one .exe file, runs just as fast as a normal script execution, and does not require a Python installed. I even took the liberty of making it have an icon with resource hacker :)

And here it is, it weights just 2.1 MB, really fricking small!
howdoi

(yes, download that png and open it as a zip file - this is so github does the hosting!)

@GUIpsp
Copy link

GUIpsp commented Jan 12, 2013

@CamiloMM Neat trick.

@gleitz
Copy link
Owner

gleitz commented Jan 13, 2013

I downloaded the PNG but I'm on a Mac without 7-zip. When I ran unzip howdoi.zip it created howdoi.zip.cpgz.

Just put the .exe in a Dropbox?

@CamiloMM
Copy link
Author

I don't use neither Dropbox nor Macs, but since it's a Unix under the hood, this should work as it does in Linux:

wget https://f.cloud.github.com/assets/2404138/61743/529cc4ec-5c79-11e2-8da1-27bc9260dac2.png -O file.zip
unzip file.zip

In other words, you just have to rename it. It gives a warning, but uncompresses it correctly anyway.
The MD5 of howdoi.exe should be: 02cad5ab928d809b3d6d35945514f9a2

@gleitz
Copy link
Owner

gleitz commented Jan 13, 2013

Thx! I put the file in my Dropbox. Will add to the github project soon.

@CamiloMM
Copy link
Author

I'm glad, someone will probably welcome it :)

By the way, since it's fixed on r57 (unlike running the script), whenever there's some major change I can make another .exe. So you or someone else can comment here and I take a look at it. I couldn't automate it so I'm not going to make one per revision, but as long as there's an important change and someone is interested I can get into it.

Still it would be awesome to get it automated. I don't use git, otherwise I'd look into making pull requests 'n stuff.

@gleitz gleitz closed this as completed in 72060a9 Jan 14, 2013
@CamiloMM
Copy link
Author

Now, I know this is a very small thing, but I think it might be good to indicate next to the download that it doesn't require Python installed - since it's just a bit below the words "requires Python", people might think the executable also does. Just the word "standalone" should be intuitive enough.

@isimmons
Copy link

Hi CamiloMM, Trying to use your exe and having two problems. I'm on a win 7 32bit pc.

  1. It triggers the UAC every time I try to run it
  2. It executes and closes before I can read what it said.

I'm running it from command line and tried both running it directly by being in the directory where it is, and also tried putting it in a directory on my system path. I don't think that's relevant but just in case.

It is trying to run as administrator but in properties it is not set to run as administrator which is why I'm guessing it is firing the UAC.

Oh and also it triggers Avast to start analyzing it. Maybe it's all because it's an unknown publisher? Anyway, any ideas how to get around this without disabling UAC?

Thanks

@CamiloMM
Copy link
Author

Hah, running XP here so I should have imagined this kind of thing would happen. It shouldn't try to run as administrator, really. I believe this is a problem with 7z sfx module, I think to avoid this one needs to add a manifest of some sort on the .exe.

(Yes, I just confirmed this is a problem with the 7z sfx module...)

Ok, I have added a manifest that should make it compatible with Vista, 7 and 8, so please test it to see if it works:
howdoi

(The manifest is embedded in the file, and hopefully you should see no more sheild overlay icon if you saw one earlier.)

@isimmons
Copy link

Yep, that fixed it. win7 puts the shield on it and wants to run it as administrator when extracted to the desktop but as soon as I copied it over to my User/bin directory it changes to normal and runs fine.

Thanks

@CamiloMM
Copy link
Author

Glad it worked @isimmons! But I didn't understand - Windows 7 has a /usr/bin equivalent?

@isimmons
Copy link

No, sorry, I just picked it up from using Linux and made my own c:\users\username\bin which is added to the system path and is where I store 3rd party exe, and my .bat, and .cmd files for easy use from the command line.

@CamiloMM
Copy link
Author

@isimmons Creative of you! I just drop them in System32 out of mere habit really.

gleitz pushed a commit that referenced this issue Jun 26, 2020
gleitz pushed a commit that referenced this issue Apr 14, 2021
# This is the 1st commit message:

move from print_err to logging

# This is the commit message #2:

change sanity check message

# This is the commit message #3:

flake8 linting

# This is the commit message #4:

flake8 linting

# This is the commit message #5:

pylint updates

# This is the commit message #6:

pylint updates

# This is the commit message #7:

pylint updates for errors.py

# This is the commit message #8:

update changes from #344

# This is the commit message #9:

update formatting

# This is the commit message #10:

update formatting

# This is the commit message #11:

add consuructor to class

# This is the commit message #12:

refactor logging levels and messages

# This is the commit message #13:

refactor logging levels and messages

# This is the commit message #14:

pylint recomendations

# This is the commit message #15:

flake8 formating

# This is the commit message #16:

flake8 formating

# This is the commit message #17:

change logging to print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants