5

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.

aneroid
  • 12,983
  • 3
  • 36
  • 66

1 Answers1

4

"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.

aneroid
  • 12,983
  • 3
  • 36
  • 66
  • The program runs OK, I was just worried it the convertion wouldn't work. Thank you for pointing out my distraction! – GetTwoBirdsStonedAtOnce Jan 24 '21 at 00:03
  • It's okay, it happens. I was looking for an option to disable the check for that one line. If the linter you're using in VSCode is Pylint (the default?) then check which option you can use to disable the error message _only for that one line_. See this [other question](https://stackoverflow.com/q/47804627/1431750) for direction. – aneroid Jan 24 '21 at 00:28