sys._MEIPASS

Here are the examples of the python api sys._MEIPASS taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

94 Examples 7

Example 1

View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = BASE_PATH
    #print "JOINING " + base_path + " WITH " + relative_path
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 2

Project: kcc
Source File: kcc.py
View license
        def __init__(self, *args, **kw):
            if hasattr(sys, 'frozen'):
                # noinspection PyProtectedMember
                os.putenv('_MEIPASS2', sys._MEIPASS)
            try:
                super(_Popen, self).__init__(*args, **kw)
            finally:
                if hasattr(sys, 'frozen'):
                    if hasattr(os, 'unsetenv'):
                        os.unsetenv('_MEIPASS2')
                    else:
                        os.putenv('_MEIPASS2', '')

Example 3

Project: aeneas
Source File: globalfunctions.py
View license
def bundle_directory():
    """
    Return the absolute path of the bundle directory
    if running from a frozen binary; otherwise return ``None``.

    :rtype: string
    """
    if FROZEN:
        return sys._MEIPASS
    return None

Example 4

Project: bitmask_client
Source File: __init__.py
View license
def here(module=None):
    if getattr(sys, 'frozen', False):
        # we are running in a |PyInstaller| bundle
        return sys._MEIPASS
    else:
        dirname = os.path.dirname
        if module:
            return dirname(module.__file__)
        else:
            return dirname(__file__)

Example 5

View license
    def __init__(self, *args, **kw):
        if hasattr(sys, 'frozen'):
            # We have to set original _MEIPASS2 value from sys._MEIPASS
            # to get --onefile mode working.
            # Last character is stripped in C-loader. We have to add
            # '/' or '\\' at the end.
            os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
        try:
            super(_Popen, self).__init__(*args, **kw)
        finally:
            if hasattr(sys, 'frozen'):
                # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                # available. In those cases we cannot delete the variable
                # but only set it to the empty string. The bootloader
                # can handle this case.
                if hasattr(os, 'unsetenv'):
                    os.unsetenv('_MEIPASS2')
                else:
                    os.putenv('_MEIPASS2', '')

Example 6

Project: fallingsky
Source File: util.py
View license
def _here():
    """Returns the current full directory path."""

    if hasattr(sys, "_MEIPASS"):  # pyinstaller deployed
        return os.path.join(sys._MEIPASS)
    else:
        return os.path.dirname(os.path.realpath(__file__))

Example 7

Project: simp_le
Source File: rthook-entrypoints.py
View license
def main():
    """Monkey-patch `pkg_resources` with correct database."""
    entry_points_path = os.path.join(sys._MEIPASS, 'entry_points.json')
    with open(entry_points_path) as fp:
        all_entry_points = json.loads(fp.read())
    patch(pkg_resources)(iter_entry_points_factory(all_entry_points))

Example 8

Project: raspmedia
Source File: ImageTransferFrame.py
View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        #print "BASE PATH FOUND: "+ base_path
    except Exception:
        #print "BASE PATH NOT FOUND!"
        base_path = BASE_PATH
    #print "JOINING " + base_path + " WITH " + relative_path
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 9

View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        #print "BASE PATH FOUND: "+ base_path
    except Exception:
        #print "BASE PATH NOT FOUND!"
        base_path = BASE_PATH
    #print "JOINING " + base_path + " WITH " + relative_path
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 10

Project: listen1
Source File: utils.py
View license
def resource_path(relative):
    """ Gets the resource's absolute path.

    :param relative: the relative path to the resource file.
    :return: the absolute path to the resource file.
    """
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)

    abspath = os.path.abspath(os.path.join(__file__, ".."))
    abspath = os.path.dirname(abspath)
    return os.path.join(abspath, relative)

Example 11

Project: EventMonkey
Source File: EventMonkey.py
View license
        def __init__(self, *args, **kw):
            if hasattr(sys, 'frozen'):
                # We have to set original _MEIPASS2 value from sys._MEIPASS
                # to get --onefile mode working.
                os.putenv('_MEIPASS2', sys._MEIPASS)
            try:
                super(_Popen, self).__init__(*args, **kw)
            finally:
                if hasattr(sys, 'frozen'):
                    # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                    # available. In those cases we cannot delete the variable
                    # but only set it to the empty string. The bootloader
                    # can handle this case.
                    if hasattr(os, 'unsetenv'):
                        os.unsetenv('_MEIPASS2')
                    else:
                        os.putenv('_MEIPASS2', '')

Example 12

Project: spimagine
Source File: spimagine_gui.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.debug("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception as e:
        logger.debug("did not find MEIPASS: %s "%e)


        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 13

Project: reddwall
Source File: reddwall.py
View license
	def __init__(self, parent):
		wx.TaskBarIcon.__init__(self)
		if getattr(sys, 'frozen', False):
			basedir = sys._MEIPASS
		else:
			basedir = os.path.dirname(__file__)
		ICON_PATH = os.path.join(basedir, "alien.png")
		self.SetIcon(wx.Icon(ICON_PATH, wx.BITMAP_TYPE_PNG), "alien")
		self.Bind(wx.EVT_MENU, parent.NextWallpaper, id=self.ID_NEW_OPTION)
		self.Bind(wx.EVT_MENU, parent.CreatePrefWindow, id=self.ID_PREF_OPTION)
		self.Bind(wx.EVT_MENU, parent.Quit, id=wx.ID_EXIT)

Example 14

Project: mastermind
Source File: cli.py
View license
def simple_mode(config):
    if not ("response-body" in config["core"] and "url" in config["core"]):
        return Exception("Simple mode requires response-body and url flags")

    script_path_template = "{}/scripts/simple.py {} {}"
    script_path = os.path.dirname(os.path.realpath(__file__))

    if getattr(sys, 'frozen', False):
        script_path = sys._MEIPASS

    script_arg = ["--script",
                  script_path_template.format(script_path,
                                              config["core"]["url"],
                                              config["core"]["response-body"])]

    return common_args(config) + script_arg + verbosity_args(config)

Example 15

Project: spimagine
Source File: glwidget.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 16

Project: SWProxy
Source File: SWProxy.py
View license
def resource_path(relative_path):
    # function to locate data files for pyinstaller single file executable
    # ref: http://stackoverflow.com/a/32048136
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

Example 17

Project: PyBitmessage
Source File: shared.py
View license
def codePath():
    if frozen == "macosx_app":
        codePath = os.environ.get("RESOURCEPATH")
    elif frozen: # windows
        codePath = sys._MEIPASS
    else:    
        codePath = os.path.dirname(__file__)
    return codePath

Example 18

Project: detekt
Source File: utils.py
View license
def get_resource(relative):
    # First try from the local directory. This might come handy in case we want
    # to provide updates or allow the user to run custom signatures.
    path = os.path.join(os.getcwd(), relative)
    # In case the resource doesn't exist in the current directory, we'll try
    # from the actual resources.
    if not os.path.exists(path):
        if hasattr(sys, '_MEIPASS'):
            path = os.path.join(sys._MEIPASS, relative)

    return path

Example 19

Project: fallingsky
Source File: util.py
View license
def _here():
    """Returns the current full directory path."""

    if hasattr(sys, "_MEIPASS"):  # pyinstaller deployed
        return os.path.join(sys._MEIPASS)
    else:
        return os.path.dirname(os.path.realpath(__file__))

Example 20

Project: listen1
Source File: utils.py
View license
def resource_path(relative):
    """ Gets the resource's absolute path.

    :param relative: the relative path to the resource file.
    :return: the absolute path to the resource file.
    """
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)

    abspath = os.path.abspath(os.path.join(__file__, ".."))
    abspath = os.path.dirname(abspath)
    return os.path.join(abspath, relative)

Example 21

Project: arkos-install
Source File: Installer.py
View license
def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

Example 22

Project: Fastir_Collector
Source File: mem.py
View license
    def __init__(self, *args, **kw):
        if hasattr(sys, 'frozen'):
            # We have to set original _MEIPASS2 value from sys._MEIPASS
            # to get --onefile mode working.
            # Last character is stripped in C-loader. We have to add
            # '/' or '\\' at the end.
            os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
        try:
            super(_Popen, self).__init__(*args, **kw)
        finally:
            if hasattr(sys, 'frozen'):
                # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                # available. In those cases we cannot delete the variable
                # but only set it to the empty string. The bootloader
                # can handle this case.
                if hasattr(os, 'unsetenv'):
                    os.unsetenv('_MEIPASS2')
                else:
                    os.putenv('_MEIPASS2', '')

Example 23

Project: Fastir_Collector
Source File: main.py
View license
def parse_config_file(config_file, param_options):
    """Parse config file specified in argument, or default config file (FastIR.conf)"""
    # If no config_file was specified, fallback to bundled config
    if not config_file:
        config_file = "FastIR.conf"
        # If app is frozen with pyinstaller, look for temporary file path
        if hasattr(sys, "frozen"):
            config_file = os.path.join(sys._MEIPASS, config_file)
    else:
        # If a config_file was specified but doesn"t exist, tell the user and quit
        if not os.path.isfile(config_file):
            sys.stderr.write("Error: config file '%s' not found" % config_file)
            sys.exit(1)

    if os.path.isfile(config_file):
        return profile_used(config_file, param_options)
    else:
        return {}

Example 24

Project: tatlin
Source File: tatlin.py
View license
def resolve_path(fpath):
    if os.path.isabs(fpath):
        return fpath

    if getattr(sys, 'frozen', False):
        # we are running in a PyInstaller bundle
        basedir = sys._MEIPASS
    else:
        # we are running in a normal Python environment
        basedir = os.path.dirname(__file__)

    return os.path.join(basedir, fpath)

Example 25

Project: eavatar-me
Source File: misc.py
View license
def resource_path(relative):
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)

    abspath = os.path.abspath(os.path.join(__file__, "..", ".."))
    abspath = os.path.dirname(abspath)
    return os.path.join(abspath, relative)

Example 26

Project: grow
Source File: utils.py
View license
def is_packaged_app():
    try:
        sys._MEIPASS
        return True
    except AttributeError:
        return False

Example 27

Project: eavatar-me
Source File: misc.py
View license
def base_path():
    if hasattr(sys, "_MEIPASS"):
        return sys._MEIPASS
    else:
        # assumes this file is located at src/ava/util/__init__.py
        abspath = os.path.abspath(os.path.join(__file__, "..", ".."))
        abspath = os.path.dirname(abspath)
        return abspath

Example 28

Project: spimagine
Source File: spimagine_gui.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.debug("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception as e:
        logger.debug("did not find MEIPASS: %s "%e)


        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 29

Project: photograbber
Source File: res.py
View license
def getpath(name=None):
    if getattr(sys, '_MEIPASS', None):
        basedir = sys._MEIPASS
    else:
        #basedir = os.path.dirname(__file__)
        basedir = os.getcwd()
        
    if name is None:
        return basedir

    return os.path.join(basedir, name)

Example 30

Project: spimagine
Source File: loadcolormaps.py
View license
def _absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.DEBUG("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 31

Project: reddwall
Source File: reddwall.py
View license
	def __init__(self, parent):
		wx.TaskBarIcon.__init__(self)
		if getattr(sys, 'frozen', False):
			basedir = sys._MEIPASS
		else:
			basedir = os.path.dirname(__file__)
		ICON_PATH = os.path.join(basedir, "alien.png")
		self.SetIcon(wx.Icon(ICON_PATH, wx.BITMAP_TYPE_PNG), "alien")
		self.Bind(wx.EVT_MENU, parent.NextWallpaper, id=self.ID_NEW_OPTION)
		self.Bind(wx.EVT_MENU, parent.CreatePrefWindow, id=self.ID_PREF_OPTION)
		self.Bind(wx.EVT_MENU, parent.Quit, id=wx.ID_EXIT)

Example 32

Project: spimagine
Source File: loadcolormaps.py
View license
def loadcolormaps():
    cmaps = {}

    try:
        basePath = sys._MEIPASS
    except:
        basePath = _absPath("../colormaps/")

    reg = re.compile("cmap_(.*)\.png")
    for fName in os.listdir(basePath):
        match = reg.match(fName)
        if match:
            try:
                cmaps[match.group(1)] = _arrayFromImage(os.path.join(basePath,fName))[0,:,:]
            except Exception as e:
                print e
                print "could not load %s"%fName

    return cmaps

Example 33

Project: raspmedia
Source File: RaspMediaControlPanel.py
View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = BASE_PATH
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 34

Project: spimagine
Source File: loadcolormaps.py
View license
def loadcolormaps():
    cmaps = {}

    try:
        basePath = sys._MEIPASS
    except:
        basePath = _absPath("../colormaps/")

    reg = re.compile("cmap_(.*)\.png")
    for fName in os.listdir(basePath):
        match = reg.match(fName)
        if match:
            try:
                cmaps[match.group(1)] = _arrayFromImage(os.path.join(basePath,fName))[0,:,:]
            except Exception as e:
                print e
                print "could not load %s"%fName

    return cmaps

Example 35

Project: SWProxy
Source File: SWProxy.py
View license
def resource_path(relative_path):
    # function to locate data files for pyinstaller single file executable
    # ref: http://stackoverflow.com/a/32048136
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

Example 36

View license
    def __init__(self, *args, **kw):
        if hasattr(sys, 'frozen'):
            # We have to set original _MEIPASS2 value from sys._MEIPASS
            # to get --onefile mode working.
            os.putenv('_MEIPASS2', sys._MEIPASS)
        try:
            super(_Popen, self).__init__(*args, **kw)
        finally:
            if hasattr(sys, 'frozen'):
                # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                # available. In those cases we cannot delete the variable
                # but only set it to the empty string. The bootloader
                # can handle this case.
                if hasattr(os, 'unsetenv'):
                    os.unsetenv('_MEIPASS2')
                else:
                    os.putenv('_MEIPASS2', '')

Example 37

Project: simp_le
Source File: rthook-entrypoints.py
View license
def main():
    """Monkey-patch `pkg_resources` with correct database."""
    entry_points_path = os.path.join(sys._MEIPASS, 'entry_points.json')
    with open(entry_points_path) as fp:
        all_entry_points = json.loads(fp.read())
    patch(pkg_resources)(iter_entry_points_factory(all_entry_points))

Example 38

Project: SWProxy-plugins
Source File: SWProxy.py
View license
def resource_path(relative_path):
    # function to locate data files for pyinstaller single file executable
    # ref: http://stackoverflow.com/a/32048136
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

Example 39

Project: libturpial
Source File: http.py
View license
    def __init__(self, base_url, proxies=None, timeout=None):
        self.base_url = base_url
        self.proxies = proxies or {}
        self.timeout = timeout or DEFAULT_TIMEOUT

        self.log = logging.getLogger('TurpialHTTP')

        try:
            # if getattr(sys, 'frozen', None):
            basedir = sys._MEIPASS
            self.ca_certs_file = os.path.realpath(os.path.join(basedir,
                                                               'cacert.pem'))
            # else:
        except:
            basedir = os.path.dirname(__file__)
            self.ca_certs_file = os.path.realpath(os.path.join(basedir,
                                                  '..', 'certs',
                                                  'cacert.pem'))

Example 40

View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = BASE_PATH
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 41

Project: bitmask_client
Source File: __init__.py
View license
def here(module=None):
    if getattr(sys, 'frozen', False):
        # we are running in a |PyInstaller| bundle
        return sys._MEIPASS
    else:
        dirname = os.path.dirname
        if module:
            return dirname(module.__file__)
        else:
            return dirname(__file__)

Example 42

Project: spimagine
Source File: glwidget.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 43

Project: padpyght
Source File: __main__.py
View license
def list_skin_paths():
    if getattr(sys, 'frozen', False):
        base_dir = os.path.join(sys._MEIPASS, 'padpyght', 'skins')
        for dir_name in os.listdir(base_dir):
            path = os.path.join(base_dir, dir_name)
            yield dir_name, path
    else:
        for dir_name in pkg_resources.resource_listdir('padpyght', 'skins'):
            path = pkg_resources.resource_filename('padpyght',
                                                   'skins/%s' % dir_name)
            yield dir_name, path

Example 44

Project: CIS-ESP
Source File: support.py
View license
def resource_path(relative_path, try_temp_path=True):
	""" Get absolute path to resource, works for dev and for PyInstaller """
	if try_temp_path:
		try:
			# PyInstaller creates a temp folder and stores path in _MEIPASS
			base_path = sys._MEIPASS
		except Exception:
			base_path = os.path.abspath(".")
	else:
		base_path = os.path.abspath(".")
		
	return os.path.join(base_path, relative_path)

Example 45

Project: spimagine
Source File: gui_utils.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.debug("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 46

Project: spimagine
Source File: gui_utils.py
View license
def absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.debug("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 47

Project: spimagine
Source File: loadcolormaps.py
View license
def _absPath(myPath):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    import sys

    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        logger.DEBUG("found MEIPASS: %s "%os.path.join(base_path, os.path.basename(myPath)))

        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)

Example 48

Project: SWProxy-plugins
Source File: SWProxy.py
View license
def resource_path(relative_path):
    # function to locate data files for pyinstaller single file executable
    # ref: http://stackoverflow.com/a/32048136
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

Example 49

Project: raspmedia
Source File: SimpleUIAppFrame.py
View license
def resource_path(relative_path):
    global BASE_PATH
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        #print "BASE PATH FOUND: "+ base_path
    except Exception:
        #print "BASE PATH NOT FOUND!"
        base_path = BASE_PATH
    #print "JOINING " + base_path + " WITH " + relative_path
    resPath = os.path.normcase(os.path.join(base_path, relative_path))
    #resPath = base_path + relative_path
    #print resPath
    return resPath

Example 50

Project: PancakeViewer
Source File: pancakeViewerApp.py
View license
        def __init__(self, *args, **kw):
            if hasattr(sys, 'frozen'):
                # We have to set original _MEIPASS2 value from sys._MEIPASS
                # to get --onefile mode working.
                os.putenv('_MEIPASS2', sys._MEIPASS)
            try:
                super(_Popen, self).__init__(*args, **kw)
            finally:
                if hasattr(sys, 'frozen'):
                    # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                    # available. In those cases we cannot delete the variable
                    # but only set it to the empty string. The bootloader
                    # can handle this case.
                    if hasattr(os, 'unsetenv'):
                        os.unsetenv('_MEIPASS2')
                    else:
                        os.putenv('_MEIPASS2', '')