0

Скомпилил .py в .exe через pyinstaller пишет local variable referenced before assigment хотя в .py и .py.exe всё работает Что делать, как быть?

код

import requests as rq
from tkinter import *
from tkinter import messagebox
import tkinter.ttk as ttk
import os
import time
import zipfile
import wget
import shutil

def show_message():
    
    loginreq = rq.post("https://www.kooft.site/login/", data={'n':name.get(),'pwd':pwd.get()})
    if 'Неверный пароль' in loginreq.text:
        messagebox.showerror(" f ", "Не удалось войти в аккаунт")
    else:
        file = open('gamedo.txt', 'w')
        f = file.write(name.get() + '/' + pwd.get())
        messagebox.showinfo(" Успешный вход ", "Перезапустите GameDo")
 

root = Tk()
root.title("gd")
root.geometry("300x250")

file = open('gamedo.txt', 'r')
f = file.read()
if not f:
    name = StringVar()
    pwd = StringVar()

    name_label = Label(text="Введите логин и пароль от аккаунта")
    name_label.grid(row=1, column=4, sticky="w")

    name_entry = Entry(textvariable=name)
    name_entry.place(relx=.5, rely=.1, anchor="c")


    pwd_entry = Entry(textvariable=pwd)
    pwd_entry.place(relx=.5, rely=.2, anchor="c")


    message_button = Button(text="Click Me", command=show_message)
    message_button.place(relx=.5, rely=.5, anchor="c")
else:
    n = f.split('/')[0]
    pwd = f.split('/')[1]
    messagebox.showinfo("logged in", f[0])
    qreq = rq.post('https://www.kooft.site/checkgames/', data={'user':f.split('/')[0]})

    frame = Frame(root)
    frame.grid()
    combobox = ttk.Combobox(frame,values = qreq.text.split(',') ,height=3)
    combobox.set(qreq.text.split(',')[0])
    combobox.grid(column=0,row=0)
    def play():
        try:
            
            game = qreq.text.split(',')[combobox.current()].replace("'", "") 
            if qreq.text.split(',')[combobox.current()] in qreq.text.split(',') and os.path.exists(os.getcwd()+game ):
                 
                 print(game)
                 vnew = rq.post('https://www.kooft.site/gamev', data={'game':game}).text
                 vnow = open(game+'/version.txt', 'r').read()
            if vnew == vnow:
                pts = os.getcwd()+os.getcwd()[2]+game+os.getcwd()[2]+"Windows"+os.getcwd()[2]+game+".exe"
                os.startfile(pts)
            else:
                shutil.rmtree(os.getcwd()+os.getcwd()[2]+game, ignore_errors=True)
                dl = wget.download("http://f0299148.xsph.ru/"+game+".zip", os.getcwd() )
                print(dl)
        except FileNotFoundError:
            print('download it')
            wget.download("http://f0299148.xsph.ru/"+game+".zip", os.getcwd() )
            print('dload')
            os.makedirs(os.getcwd()+os.getcwd()[2]+game)
            ex = zipfile.ZipFile(os.getcwd()+os.getcwd()[2]+game+".zip", 'r')
            ex.extractall(os.getcwd()+os.getcwd()[2]+game)
            ex.close()
            
            
            
    
    message_button = Button(text="Play", command=play)
    message_button.place(relx=.5, rely=.5, anchor="c")

    
        
        



root.mainloop()
2
  • Похоже у вас где-то в коде local variable referenced before assigment. Можете скинуть код?
    – timur
    29 июн 2020 в 17:38
  • Отредактировал вопрос, вставил код
    – lisky
    29 июн 2020 в 17:43

1 ответ 1

0
if qreq.text.split(',')[combobox.current()] in qreq.text.split(',') and 
    os.path.exists(os.getcwd()+game ):
    print(game)
    vnew = rq.post('https://www.kooft.site/gamev', data={'game':game}).text
    vnow = open(game+'/version.txt', 'r').read()
if vnew == vnow: # vnew и vnow объявлены в другом блоке кода и недоступны здесь
    #...
try:
    game = qreq.text.split(',')[combobox.current()].replace("'", "") 
except FileNotFoundError:
    print('download it')
                                  # то же самое с переменной game
    wget.download("http://f0299148.xsph.ru/"+game+".zip", os.getcwd()) 

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.