24

What is sys._MEIPASS. What is the value of this variable and it's use ? I was a looking one python script but when I ran it on eclipse(pydev). It showing error.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Kumar Roshan Mehta
  • 3,078
  • 2
  • 27
  • 50

3 Answers3

30

sys._MEIPASS is a temporary folder for PyInstaller. See this question for more information.

Community
  • 1
  • 1
NorthCat
  • 9,643
  • 16
  • 47
  • 50
9

This is the path attribution created by pyinstaller, it is quite useful when you have some resource files (like .bmp .png) to load in your python one-file-bundled app.

When a bundled app starts up, the bootloader sets the sys.frozen attribute and stores the absolute path to the bundle folder in sys._MEIPASS. For a one-folder bundle, this is the path to that folder. For a one-file bundle, this is the path to the temporary folder created by the bootloader.

a typical use would be:

from pathlib import Path
import sys

if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
    bundle_dir = Path(sys._MEIPASS)
else:
    bundle_dir = Path(__file__).parent

path_to_dat = Path.cwd() / bundle_dir / "other-file.dat"

You may want to check details here: https://pyinstaller.readthedocs.io/en/stable/runtime-information.html

Can
  • 171
  • 2
  • 3
0

If you want to disable the error Lint gives you in your editor (Eclipse, MS-Code, ...) add the following comment at end of your line:

if getattr(sys, 'frozen', False): # Running as compiled
        running_dir = sys._MEIPASS + "/files/" # pylint: disable=no-member

The solution was from here if you want to disable a single line of code, not all errors of a kind.

Le Droid
  • 4,534
  • 3
  • 37
  • 32