0

I created a small program in python using a few imports:

splinter, Tkinter, webbrwoser, urllib, and re

The program has a GUI (through tkinter), and everything works fine when I run it through the command line.

However, when I try to create an executable file using these instructions, everything seems to work but then when I actually run the .exe file, I get the following error:

C:\Python27\dist>pypy.exe
Traceback (most recent call last):
  File "pypy.py", line 1, in <module>
ImportError: No module named splinter

This is the code I used to get the .exe file:

from distutils.core import setup
import py2exe

setup(console=['pypy.py'])

So I'm guessing (after doing some reading in this SO post) the problem has something to do with missing files from my dist folder, but for the life of me I'm not sure where to go from here.

Please help me make my GUI python program work.

Thanks in advance,

Jona

Community
  • 1
  • 1
Jona
  • 1,023
  • 2
  • 15
  • 39

2 Answers2

0

I found this post which discusses manually -excluding- modules from a py2exe build: py2exe "include" modules: when should they be managed manually?

They mention that tk is automatically included and I'd suspect re and webbrowser/urllib as standard packages would also be, but others may need to be added in the 'include' section. I suspect you need something like the following in your setup:

setup(
        console=['pypy.py'],
        options={
                "py2exe":{
                        "includes": ["splinter"]
                }
        }
)

Hopefully this helps; I haven't done much with py2exe, so if not maybe someone else can help!

Community
  • 1
  • 1
  • i figured it would be something similar, but i don't think i can just write "includes: [splinter]" - from my vague understanding i need a list of files, only I'm not sure if (a) i'm right, and (b) if i'm right, which files – Jona Jan 24 '16 at 21:40
  • From what I can see, the line would be 'includes: ["splinter"]', with the double quotes around the package name. I have also read that if the module is imported in the setup.py, it will be included, so a work-around would be to import splinter in the setup (pretty nasty if it does work). You could also try 'packages': ['splinter']. – A Small Shell Script Jan 24 '16 at 22:34
  • unfortunately i still get "No module named splinter", execept now it's when I try to run the py2exe setup :/ – Jona Jan 25 '16 at 16:40
  • You may want to do some reading on how to package/deploy python code. You could add splinter to the sys.path temporarily, but I have a feeling that py2exe is not smart enough to follow a dependency like this. http://stackoverflow.com/questions/34983860/where-to-save-python-modules/34984560#34984560 – A Small Shell Script Jan 26 '16 at 19:40
0

ok! after quite a bit of digging (here, here, and here) I got it all to work!

Steps:

  1. Copy the whole splinter folder to Python27\Lib\site-packages before running the setup.py
  2. Copy both "webdriver.xpi" and "webdriver_prefs.json" from C:\Python27\Lib\site-packages\selenium\webdriver\firefox to dist\selenium\webdriver\firefox after the setup (once the dist folder is created)
  3. Bonus: for the .exe to open without the console (good if you're using a GUI), in the setup.py file use windows instead of console in setup(console=['pypy.py'])

And that's it! Now the program runs and works with the GUI and splinter libraries sans hitch!

Community
  • 1
  • 1
Jona
  • 1,023
  • 2
  • 15
  • 39