使用 Pyinstaller 将 PRAW python 文件转换为 exe 时出现“AttributeError: '_NotSet' object has no attribute 'lower'”

Rec*_*ive 4 python pyinstaller attributeerror praw

正如标题所说。

当我执行转换后的 python 文件(.exe)时,我得到以下输出:

Traceback (most recent call last):
  File "background.py", line 10, in <module>
  File "site-packages\praw\reddit.py", line 129, in __init__
  File "site-packages\praw\config.py", line 72, in __init__
  File "site-packages\praw\config.py", line 98, in _initialize_attributes
  File "site-packages\praw\config.py", line 31, in _config_boolean
AttributeError: '_NotSet' object has no attribute 'lower'
[1692] Failed to execute script background
Run Code Online (Sandbox Code Playgroud)

我没有使用 praw.ini 文件,而是将登录值硬编码为:

import praw
import praw.models
import urllib.request
from random import randint
from os import getcwd
import ctypes

r = praw.Reddit(client_id='client',
                     client_secret='secret',
                     user_agent='user')
sub = r.subreddit('earthporn')
choose = []
for i in sub.hot(limit=20):
    a = str(i.url)
    if "i.redd" in a or "i.imgur" in a:
        choose.append(i.url)
x = choose[randint(0,len(choose)-1)]
resource = urllib.request.urlopen(x)
output = open("daily_image.jpg","wb")
output.write(resource.read())
output.close()


direc = getcwd() + "\\daily_image.jpg"
ctypes.windll.user32.SystemParametersInfoW(20, 0, direc , 0)
Run Code Online (Sandbox Code Playgroud)

上面的文件只在 python 中有效,但在转换为 exe 时无效。(显然与客户端,秘密和用户ID的设置,随意窃取它idrc)

任何帮助真的很感激!

小智 6

我遇到了这个错误,发现要解决它,您需要praw.ini在运行可执行文件 ( your_app.exe)的目录中拥有 的副本。您可以praw.ini在安装\praw目录中找到您的。


Rec*_*ive 3

正确的。

因此,pyinstaller 并不是一个完美的 .py 到 .exe 转换器,因此有些内容在翻译过程中会丢失。

我首先注释掉了 praw 中的所有更新,因为这导致 pyinstaller 创建的 .exe 崩溃(请注意,我在这里所做的所有操作都导致 .exe 中出现错误,但从未在 .py 中出现错误)。

然后我必须手动设置一些变量,因为它们在 .exe 版本中调用时没有设置。要么在 PRAW 中使用线程,而在 .exe 版本中它无法跟上,要么发生了一些非常奇怪的事情。

是的,所以我基本上只是修改了整个 praw 的代码,这样这个东西就能运行。如果有人像我一样遇到这个问题,并且在任何地方都找不到答案(因为相信我,我搜索了地球,但没有找到它),请给我发消息,我可以向您发送我的原始版本。

愿上帝禁止你犯这个错误