简体   繁体   中英

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 --hidden-import "os" filename.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM