gpt4 book ai didi

python - 模块 'sys' 没有 '_MEIPASS' 成员

转载 作者:行者123 更新时间:2023-12-05 04:54:07 30 4
gpt4 key购买 nike

所以我正在学习如何将我的 python 项目转换为可执行文件的教程:https://dev.to/eshleron/how-to-convert-py-to-exe-step-by-step-guide-3cfi

我需要编写这个函数:

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)

但是 VSCode 给我这个错误:模块“sys”没有“_MEIPASS”成员。网上找了好久,还是不知道怎么解决。

最佳答案

"And I needed to write this function"

如果您阅读 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:

这是 PyInstaller 设置的东西。默认情况下,它不是 sys 中的东西。 VSCode 是在您尝试执行时抛出错误还是只是在 IDE 中发出警告?可能是后者。

关于python - 模块 'sys' 没有 '_MEIPASS' 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65865523/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com