1

I wrote a small python program in 3.6 to automate a task I do monthly at work. It could be useful to other people I work with, so I've been trying to bundle it with Pynsist.

Before bundling, the program runs successfully both from IDLE and the windows command line. After bundling and installation via the .exe, I receive an error stating:

Traceback (most recent call last): File "C:\Program Files\Time Clocker\timeClocker.py", line 7, in from selenium import webdriver ModuleNotFoundError: No module named 'selenium'

Selenium isn't the first module that gets imported in my code, so it seems the others are being bundled correctly and the issue is just with selenium.

I've tried including some selenium files in a pynsist_pkgs folder, but that doesn't work either. Here are those files, not sure if they are the right ones.

04/04/2017  02:25 PM            19,057 CHANGES
03/08/2017  07:00 AM               915 MANIFEST.in
04/04/2017  02:28 PM             7,864 PKG-INFO
04/04/2017  08:11 AM             5,719 README.rst
04/13/2017  04:50 PM    <DIR>          selenium
04/13/2017  04:50 PM    <DIR>          selenium.egg-info
04/04/2017  02:28 PM               230 setup.cfg
04/04/2017  02:26 PM             3,806 setup.py
               6 File(s)         37,591 bytes

Here is my installer.cfg file for reference:

[Application]
name=Time Clocker
version=1.0
package:
script=timeClocker.py
console=true    

[Python]    

version=3.6.1    

[Include]    

packages = selenium
     re
     getpass    

files = chromedriver.exe

If anyone has any ideas, that would be greatly appreciated!

Auraten
  • 11
  • 3
  • When you build it with Pynsist, you should get a folder `build/nsis`. Looking in there, can you see if `pkgs/selenium/__init__.py` exists? – Thomas K Apr 20 '17 at 16:45
  • @ThomasK It does exist, and it also exists in the Program Files app folder after installed. – Auraten Apr 20 '17 at 16:52
  • Ah, I know. You're using the `script=` option in installer.cfg. In general, I strongly recommend using the `entry_point=` option instead of script - with that, you give it a function to call to launch your application. See [the docs](http://pynsist.readthedocs.io/en/latest/cfgfile.html). If you do use `script=`, you need some boilerplate at the top of the script - that's also in the docs. – Thomas K Apr 20 '17 at 17:43
  • 1
    @ThomasK Looks like that worked! I had to rearrange my not so well structured code to have a main function, and ensure certain variables were globally accessible, but changing to the entry_point method was the key. Thanks so much for your time! – Auraten Apr 20 '17 at 18:17

1 Answers1

1

Reposting as an answer so it's clear to other people who come across this.

The installer.cfg file uses script= to define how to launch the application. It's recommended to use entry_point= instead to specify a function, like:

entry_point=my_module:main

The documentation has more info on what this does.

If you do need to use a script, make sure that it has some boilerplate at the top before it tries to import packages:

import sys
sys.path.insert(0, 'pkgs')

Using entry_point= allows Pynsist to automatically add this boilerplate and more (e.g. to better handle uncaught exceptions in GUI apps). This is why I'd always recommend that over script=. A future version of Pynsist may even remove the option to specify a script.

Thomas K
  • 39,200
  • 7
  • 84
  • 86