Исполняемый файл PyInstaller не может запустить операцию загрузки с помощью внешнего скрипта, несмотря на работу на чистPython

Программы на Python
Anonymous
Исполняемый файл PyInstaller не может запустить операцию загрузки с помощью внешнего скрипта, несмотря на работу на чист

Сообщение Anonymous »

Я пытаюсь скомпилировать скрипт Python в исполняемый файл, но не могу правильно подключить внешний файл tg-upload.py, который отвечает за операции загрузки.
соответствующий код в моем telethongram.py:

Код: Выделить всё

def download_thread():
while True:
link = download_queue.get()
if link is None:
break  # Termina il thread
download_link_script(link)
download_queue.task_done()

download_thread = Thread(target=download_thread)
download_thread.start()

def download_link_script(link):
print(f'Chiamato download_link_script con il link: {link}')

# Ottieni il percorso del file tg-upload.py
if getattr(sys, 'frozen', False):
# Se l'applicazione è congelata, ottieni il percorso del file dal bundle
tg_upload_path = os.path.join(sys._MEIPASS, 'tg-upload.py')
else:
# Se l'applicazione non è congelata, usa il percorso relativo
tg_upload_path = 'tg-upload.py'

print(f'Percorso tg-upload.py: {tg_upload_path}')

command = [sys.executable, tg_upload_path, '--profile', 'enteSoffitta', '--dl', '--links'] + link.split()
print(f'Comando eseguito: {" ".join(command)}')

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
progress_updates = []  # Create an array to hold the progress updates
while True:
output = process.stdout.readline()
if output == b'' and process.poll() is not None:
break
if output:
try:
output = output.decode('utf-8')  # Decode the bytes to a string
except UnicodeDecodeError:
output = output.decode('latin-1')  # Fallback to latin-1 decoding
print(output.strip())
match = re.search(r'(\d+(\.\d+)?%)', output.strip())  # Extract the progress percentage
if match:
progress_updates.append(match.group(1))  # Add progress update to array

# Cattura e stampa l'output di errore
stderr_output = process.stderr.read()
if stderr_output:
try:
stderr_output = stderr_output.decode('utf-8')
except UnicodeDecodeError:
stderr_output = stderr_output.decode('latin-1')
print(f'Errore: {stderr_output}')

rc = process.poll()
return jsonify(progress_updates)  # Send progress updates as JSON

@app.route('/scarica', methods=['GET'])
def scarica():
print('Ricevuta richiesta GET a /scarica')
link = request.args.get('message_link')
if link:
response = download_link_script(link)  # Get the Response object
return response  # Return the Response object directly
else:
return jsonify({'error': 'Nessun message_link fornito'}), 400

@app.route('/scarica_multi', methods=['POST'])
def scarica_multi():
print('Ricevuta richiesta POST a /scarica_multi')
links = request.json.get('message_link')
if links:
for link in links:
download_queue.put(link)  # Aggiungi ogni link alla coda
return jsonify({'message': 'Download iniziati'})
else:
return jsonify({'error': 'Nessun message_link fornito'}), 400

if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=False)
download_queue.put(None)
download_thread.join()
Для компиляции в Windows я пытаюсь включить файл таким образом

Код: Выделить всё

pyinstaller --onefile --add-data "tg-upload.py:." --add-data "static:static" --add-data "templates:templates" telethongram.py
но проблема в том, что даже если он включен, то операции загрузки не начинаются с экзешника telethongram.exe, а с чистым питоновым скриптом у меня нет проблем со скачиванием с помощью tg- upload.py
Существует проблема с импортом tg-upload.py в исполняемый файл telethongram.exe
Также в Linux проблема такая же

Подробнее здесь: https://stackoverflow.com/questions/790 ... cript-desp

Вернуться в «Python»