简体   繁体   English

Pyinstaller.exe 不能使用带有 __file__ 的模块

[英]Pyinstaller .exe cannot use module with __file__

guys!伙计们! I have a question and need your help!我有一个问题,需要你的帮助!

The question: I have a main Python script named client.py and in it, I import a module called stata_setup.config .问题:我有一个名为client.py的主要 Python 脚本,并在其中导入了一个名为stata_setup.config的模块。 But there is a if statements in config.py to judge whether the directory of __file__ is right, so after pyinstaller, when I run the client.exe , it always raise error: "failed to load Stata's shared library" .但是config.py中有一个if语句判断__file__的目录是否正确,所以在pyinstaller之后,当我运行client.exe时,总是报错: “failed to load Stata's shared library” The error and the related codes in config.py are as follows: config.py中的错误及相关代码如下:

def _get_st_home():
pypath = os.path.normpath(os.path.abspath(__file__))
d_utilities = dirname(dirname(pypath))

if os.path.basename(d_utilities).lower()=="utilities":
    return dirname(d_utilities)
else:
    _RaiseSystemException("failed to load Stata's shared library")

The reason: After searching and learning, I know it's because that the pyinstaller's bootloader changes original directory.原因:经过搜索和学习,我知道是因为pyinstaller的bootloader改变了原来的目录。

Can anyone please help me?谁能帮帮我吗? I know the reason, but I don't know how to solve it.我知道原因,但我不知道如何解决。

Thanks!谢谢!

try this method: if os.path.isfile('./stata_setup.config'): .试试这个方法: if os.path.isfile('./stata_setup.config'): the '.'这 '。' looks for the file if its in the same directory as the script.如果该文件与脚本位于同一目录中,则查找该文件。 if you file is in a folder then it'd look like this if os.path.isfile('./folder/stata_setup.config') .如果您的文件在文件夹中,那么if os.path.isfile('./folder/stata_setup.config')看起来像这样。 for what ever reason pyinstaller doesn't like using (__file__)出于什么原因 pyinstaller 不喜欢使用(__file__)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM