Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

python - Module 'sys' has no '_MEIPASS' member

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.

question from:https://stackoverflow.com/questions/65865523/module-sys-has-no-meipass-member

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...