Module 'sys' has no '_MEIPASS' member

Viewed 3505

So I was following this tutorial on how to convert my python project to an executable file: https://dev.to/eshleron/how-to-convert-py-to-exe-step-by-step-guide-3cfi

And I needed to write this function:

def resource_path(relative_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 = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

However VSCode is giving me this error: Module 'sys' has no '_MEIPASS' member. I have searched online for quite a long time and I still don't know how to fix it.

1 Answers

"And I needed to write this function"

If you read the post from where you copied it:

Newer versions of PyInstaller do not set the env variable anymore... Now the path gets set as sys._MEIPASS:

It's something PyInstaller sets. It's not something that's in sys by default. Is VSCode throwing an error when you try to execute or just a warning in the IDE? Probably the latter.

Related