#python #exe
#питон #exe — файл #python #exe
Вопрос:
- итак , это мой код , и я действительно хотел бы сделать его автономным исполняемым файлом , и я использую python 3.8.3 .
- если у вас есть какие-либо предложения по улучшению или вам удалось найти способ сделать это, я был бы очень рад.
- я уже пробовал command-cd C:UserschrisOneDriveDesktopK.A.T затем ai offline ввел это, а затем ввел команду- pyinstaller —onefile K.A.T_AI_offline.py
- но в конечном итоге это не работает, и это дает мне файл в папке dist.
- поэтому, пожалуйста, не могли бы вы помочь мне создать автономный исполняемый файл, чтобы я мог показать его своему учителю информатики и моим друзьям, не загружая python и другие модули.
# All the modules being imported
import sys
import time
from tkinter import Tk, messagebox, simpledialog
import PySimpleGUI as sg
import pyttsx3
# The voice settings
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id) #changing index changes voices but ony 0 and 1 are working here
# This creates a dictionary
the_master = {}
the_world = {}
the_word= {}
# Defining how to read the info in capital_data.txt
def read_from_file():
with open('capital_data.txt') as file:
for line in file:
line = line.rstrip('n')
country, city = line.split('/')
the_world[country] = city
# Defining how to write new info in new_data.txt
def write_to_file(country_name, city_name):
with open('new_data.txt', 'a') as file:
file.write('n' country_name '/' city_name)
def read_from_master_file():
with open('master_data.txt') as file:
for line in file:
line = line.rstrip('n')
MName, MName = line.split('/')
the_master[MName]= MName
def write_to_master_file(master_name):
with open('master_data.txt', 'a') as file:
file.write('n' master_name '/' master_name)
def read_from_alphabet_file():
with open('phonetic_alphabet.txt') as file:
for line in file:
line = line.rstrip('n')
letter, word = line.split('/')
the_word[letter] = word
# Popup box to ask wether K.A.T know this user
sg.theme('DarkBlack')
layout =[[sg.Text('Are You One Of My Masters')],
[sg.ReadFormButton('Yes'),sg.ReadFormButton('No')]]
form = sg.FlexForm('Do I Know You')
form.Layout(layout)
engine.say('are you already one of my masters')
engine.runAndWait()
button, values = form.Read()
if button is button == 'No':
form.close()
print ('Well In That Case')
print ('Hello user'), engine.say('well, in that case, Hello user'), engine.runAndWait(), print ('I am KAT'), engine.say('I am KAT'), engine.runAndWait(), print ('Which stands for Know.Alot.of.Things'), engine.say('Which stands for, Know a lot of things'), engine.runAndWait()
# see's if K.A.T know the Master
if button is button == 'Yes':
form.close()
engine.say('oh, so which master are you?')
engine.runAndWait()
root = Tk()
root.withdraw()
read_from_master_file()
query_master = simpledialog.askstring('Name Of Master', 'Which Master Are You?')
query_master = query_master.capitalize()
if query_master in the_master:
master_result = the_master[query_master]
engine.say('My apologies master,' master_result)
engine.runAndWait()
choice_of_country = ('Would you like to know the Capital city of a Country')
choice_of_phonetic_alphabet = ('Would you like to know how to spell a word or letter in the Phonetic Alphabet')
yes_master = print (choice_of_country), engine.say('Would you like to know the Capital city of a Country.'), engine.runAndWait(), print ('OR'), engine.say('or.'), engine.runAndWait, print (choice_of_phonetic_alphabet), engine.say('Would you like to know how to spell a word or letter in the Phonetic Alphabet'), engine.runAndWait(), engine.say('Which one would you like to know, just type 1 or 2'), engine.runAndWait(),
choice = input('Which one would you like to know, just type 1 or 2')
else:
engine.say('sorry you are not one of my masters')
engine.runAndWait()
if button is button == 'No':
form.close()
engine.say('oh, and, please may you enter the name, that you wish to be called.')
engine.runAndWait()
root = Tk()
root.withdraw()
new_master = simpledialog.askstring('New Master',
'Oh And Please May You Enter the name that you wish to be called')
new_master = new_master.capitalize()
if new_master == 'Oliver' :
print('OH well in that case you can just')
engine.say('OH well in that case you can just')
print('GET LOST')
engine.say('GET LOST')
engine.runAndWait()
sys.exit(0)
elif new_master in the_master:
print('You Are A Master Silly.')
engine.say('you are already a master, silly, you, are master, ' new_master)
engine.runAndWait()
write_to_master_file == False
elif new_master != 'Oliver':
write_to_master_file(new_master)
root.destroy()
engine.say('hello,' new_master)
engine.runAndWait()
choice_of_country = ('Would you like to know the Capital city of a Country')
choice_of_phonetic_alphabet = ('Would you like to know how to spell a word or letter in the Phonetic Alphabet')
no_master = print (choice_of_country), engine.say('Would you like to know the Capital city of a Country.'), engine.runAndWait(), print ('OR'), engine.say('or.'), engine.runAndWait, print (choice_of_phonetic_alphabet), engine.say('Would you like to know how to spell a word or letter in the Phonetic Alphabet'), engine.runAndWait(), engine.say('Which one would you like to know, just type 1 or 2'), engine.runAndWait(),
choice = input('Which one would you like to know, just type 1 or 2')
if simpledialog in (None, 'Ok'):
root.destroy()
new_master = new_master.capitalize()
new_master = simpledialog.askstring('New Master',
'Oh And Please May You Enter the name that you wish to be called')
the_master[new_master] = new_master
if choice == '1' :
capital_cities = ('Well just type in the Country into the little window that will pop up and i'll tell you the Capital City')
print (capital_cities)
engine.say('Well just type in the Country into the little window that will pop up and i'll tell you the Capital City')
engine.runAndWait()
# Creates the Tkinter window
root = Tk()
root.withdraw()
read_from_file()
engine.say('Now, type the name of the country you would like to know the capital city of.')
engine.runAndWait()
while True:
query_country = simpledialog.askstring('Country', 'Type the name of a country:')
query_country = query_country.capitalize()
if query_country in the_world:
result = the_world[query_country]
messagebox.showinfo('Answer',
'The capital city of ' query_country ' is ' result '!')
engine.say('The capital city of ' query_country ' is ' result)
engine.runAndWait()
else:
new_city = simpledialog.askstring('Teach me',
'I don't know! '
'What is the capital city of ' query_country '?')
engine.say('i don't know!'
'what the capital city of' query_country 'is'
'but if you know you can type it in the box')
engine.runAndWait()
the_world[query_country] = new_city
write_to_file(query_country, new_city)
break
elif choice == '2' :
phonetic_alphabet = ('Well just type in the Word or Letter into the little window that will pop up and i'll tell you how to write it out, but in using the phonetic alphabet')
print (phonetic_alphabet)
read_from_alphabet_file()
engine.say('Well just type in the Word or Letter into the little window that will pop up and i'll tell you how to write it out, but in using the phonetic alphabet')
engine.runAndWait()
root = Tk()
root.withdraw()
while True:
query_word = simpledialog.askstring('Word', 'Type a word or letter :')
if query_word in the_word:
word_result = the_word[query_word]
messagebox.showinfo('Answer',
'The way you would say' query_word ' in the phonetic alphabet is ' word_result '!')
engine.say('the way you would say' query_country 'in the phonetic alphabet is' result)
engine.runAndWait()
break
Ответ №1:
Я думаю, что причина, по которой у вас это не сработало, заключается в том, что у вашего exe есть зависимости, поэтому вам нужно извлечь его из папки dist и выполнить из основной папки вашего проекта, чтобы он мог получить доступ к зависимостям
Вот ссылка, которая должна рассказать вам все, что вам нужно знать об этом: PyInstaller
Комментарии:
1. Вы приветствуете, если это сработало для вас, не могли бы вы принять мой ответ в качестве решения? Спасибо