Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Trouble in building executable

I'm a python programmer and I'm trying to build an executable binary to distribute my software to my clients, even if it's not fully executable I want to be able to distribute my software in a way so that it is convenient for the end user.

I have already tried PyInstaller as well as Py2Exe and I'm facing the same problem with a particular software.

I used the splinter module for my program (which of course is a new high level framework to interact with other frameworks like Selenium) and every time I try to compile it there seems to be a file called "webdriver.xpi" that is always left out from the final package and therefore when the program attempts to execute the web-driver it fails with an IO Error saying that the file "webdriver.xpi" was not found....but other than that the GUI and everything works perfectly fine.

So is there a way to include it even manually? I tried including it manually by browsing to the specific folder @ library.zip file but it didn't work.

I'm not really expert in this matter and I rely on GUI2Exe for building everything...and I would really appreciate some advice if possible on how to fix this.

Thanks.

like image 545
Chacha Chowdhury Avatar asked Oct 09 '11 06:10

Chacha Chowdhury


People also ask

Can Python make executable?

Underneath the GUI is PyInstaller, a terminal based application to create Python executables for Windows, Mac and Linux. Veteran Pythonistas will be familiar with how PyInstaller works, but with auto-py-to-exe any user can easily create a single Python executable for their system.

Which is better PyInstaller or py2exe?

In PyInstaller it is easy to create one exe, By default both create a bunch of exes & dlls. In py2exe its easier to embed manifest file in exe, useful for run as administrator mode in windows vista and beyond. Pyinstaller is modular and has a feature of hooks to include files in the build that you like.

Does PyInstaller EXE require Python?

They do not need to have Python installed at all. The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for: a different OS.


3 Answers

I was at this all day and found a workaround, it's sneaky but it works. In the error message I was receiving I noticed that there was a space between in library .zip. I could not trace it down in the source code for py2exe or selenium. I too had tried putting the xpi file in the library zip and it did not work. The workaround is:

  1. In your setup file use these options:

    setup(
        console=['yourFile.py'],
        options={
                "py2exe":{
                        "skip_archive": True,
                        "unbuffered": True,
                        "optimize": 2
                }
        }
    )
    
  2. Run the py2exe install

  3. Copy the xpi file into the dist directory

That should do it.

like image 77
aknatn Avatar answered Oct 20 '22 00:10

aknatn


You need an instruction in your setup.py to include any resource files in your distribution. There is a couple of ways of doing this (see distutils, setuptools, distribute - depending on what you are using to build your distribution), but the py2exe wiki has an example.

You may need to use this py2exe tip to find your resources if you're installing them into the same directory as your exe.

See this answer for some additional info on including resource files in your distribution.

like image 44
Mark Gemmill Avatar answered Oct 20 '22 01:10

Mark Gemmill


Here is a solution of your question: I have modify a code little and it should be work since I had a same issue and I solved it:

from distutils.core import setup
import py2exe

wd_base = 'C:\\Python27\\Lib\site-packages\\selenium-2.44.0-py2.7.egg    \\selenium\\webdriver'
RequiredDataFailes = [
('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]

setup(
windows=[{"script":"gui_final.py"}],options={"py2exe":{"skip_archive": True,"includes":["sip"]}},
data_files=RequiredDataFailes,

)
like image 30
gaurang Avatar answered Oct 20 '22 00:10

gaurang