问题
As the title says.
When I execute the converted python file (the .exe) I get the following output:
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
I did not use a praw.ini file, instead hardcoding the values for the logon as such:
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)
The above file works in just python but not when converted to an exe. (obviously with the client,secret and user id's set, feel free to steal it idrc)
Any help is really appreciated!
回答1:
I had this error and found that to resolve it you need to have a copy of the praw.ini
in the directory where you a running the executable (your_app.exe
) from. You can find your praw.ini
in your installed \praw
directory.
回答2:
Right.
So, pyinstaller isn't a perfect .py to .exe converter, so some things get lost in translation.
I first commented out all updating in praw as this caused a crash in the .exe created by pyinstaller (note everything I did here caused errors in the .exe but never in the .py).
I then had to manually set some variables along the way because they weren't set when they were called in the .exe version. Either threading is used in PRAW and in the .exe version it can't keep up, or there's some seriously weird shit going on.
Yeh so I basically just modified code all throughout praw so this thing would run. If anyone comes across this issue like me and can't find the answer anywhere (because trust me I scoured planet Earth and it's no where to be found) message me and I can send you my praw version.
May god forbid you get this error
来源:https://stackoverflow.com/questions/49916290/attributeerror-notset-object-has-no-attribute-lower-when-a-praw-python-f