Python Forum
Converting py to exe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Converting py to exe (/thread-41606.html)



Converting py to exe - WiPi - Feb-16-2024

Hi all,
I am using PyInstaller to convert a python script to a windows exe file.
The python script is:
#!/usr/bin/python

import requests
import random
import time
import datetime
from datetime import date
import csv
import sys
import lxml.html
import pandas as pd
from bs4 import BeautifulSoup as bs
import json
import xlwings as xw
import schedule
import os


symbol = "XAUUSD"

file = 'C:\\Users\\Admin\\Desktop\\MyFxBookAPIData.xlsm'

try:
    wb = xw.Book(file)
    sht1 = wb.sheets[0]
    sht1.copy(name = symbol)    # copy the template to a new sheet
    sht1 = wb.sheets[symbol]
    cellA = sht1.range('A2')
    cellA.value = sht1.name

except Exception as e:
    print(str(e))
    time.sleep(60)

This works perfectly as a python script but when I convert to exe and run the file I get this error:

(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)

Any ideas please?


RE: Converting py to exe - sim - Mar-20-2024

Hello, I just created a script with tkinter and want to use pyinstaller to create an executable file. It all works, except, when I open the file I get

/Users/*********/dist/python\ Script ; exit;
Traceback (most recent call last):
File "python Script.py", line 2, in <module>
NameError: name 'tkinter' is not defined
[16411] Failed to execute script 'python Script' due to unhandled exception!

I am on a Mac and using terminal.
Any ideas?


RE: Converting py to exe - WiPi - Apr-19-2024

I think the subject of converting py to exe files is obviously a very difficult one even for the gurus judging by the number of replies!


RE: Converting py to exe - DPaul - Apr-19-2024

Even non-guru's would like to know what command line you are using:
something like pyinstaller --clean -- windowed ...etc
Paul


RE: Converting py to exe - WiPi - Apr-19-2024

(Apr-19-2024, 08:50 AM)DPaul Wrote: Even non-guru's would like to know what command line you are using:
something like pyinstaller --clean -- windowed ...etc
Paul

ah ok. So I installed auto-py-to-exe then ran this from the console. It says it converts successfully but when I run the exe file it starts to run i.e the Excel file opens which is a good start then it shows the error message in the console. So it maybe doesn't like the range command in the py script.


RE: Converting py to exe - deanhystad - Apr-19-2024

Doesn't matter if you use auto py to exe or pyinstaller. What arguements did you use to make the exe?

Is your posted code the real code that generated the error? Why all the unused imports?


RE: Converting py to exe - WiPi - Apr-19-2024

(Apr-19-2024, 02:07 PM)deanhystad Wrote: Doesn't matter if you use auto py to exe or pyinstaller. What arguements did you use to make the exe?

Is your posted code the real code that generated the error? Why all the unused imports?

yeh I know about imports - just a file I used a few times.

if you know auto py a console window comes up and you choose a few options.

'one file'
'console'
all other options ticked.

sorry don't know how to paste an image in here - it asks for a url???


RE: Converting py to exe - deanhystad - Apr-19-2024

What about 'C:\\Users\\Admin\\Desktop\\MyFxBookAPIData.xlsm'? Did you include that as an extra file?


RE: Converting py to exe - WiPi - Apr-21-2024

(Apr-19-2024, 03:37 PM)deanhystad Wrote: What about 'C:\\Users\\Admin\\Desktop\\MyFxBookAPIData.xlsm'? Did you include that as an extra file?

yes tried that but still get same error message