PyInstaller - How do you handle environmental variables?


PyInstaller - How do you handle environmental variables?



Background:



I am trying to convert a python script to an executable file that can be used on other computers. I decided to use PyInstaller. I am using Python 2.7.13/Anaconda 2.2.0 (64-bit). I have of course seen many examples and I can achieve this for basic examples. However, the script I am now working on uses environmental variables. The following block of code appears at the start of my python script:


import os
# force qt4
os.environ['ETS_TOOLKIT'] = 'qt4'
os.environ['QT_API'] = 'pyqt'

from traits.api import HasTraits, Range, Instance, Button, on_trait_change, Bool, Str, Enum, Float, Int
from traitsui.api import View, Item, Group, HGroup, spring, Handler, Action, InstanceEditor, Menu, MenuBar, message,
Tabbed
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel
from pyface.api import FileDialog, OK
import yaml
from mayavi import mlab
import numpy as np
from collections import namedtuple
import gdal



Problem:



Running pyinstaller --onefile filename.py on the command line produces an .exe, but it doesn't run because of the error: ImportError: No module named qt4."qt4" isn't a module, so I am assuming the problem is with the line " os.environ['ETS_TOOLKIT'] = 'qt4'".
After looking at various questions related to PyInstaller, I know how to use 'hiddenimports', but I have no idea how to handle environmental variables. Obviously something like pyinstaller --onefile --hidden-import qt4 filename.py didn't work.


pyinstaller --onefile filename.py


.exe


ImportError: No module named qt4


os.environ['ETS_TOOLKIT'] = 'qt4


pyinstaller --onefile --hidden-import qt4 filename.py









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy