0

I have a 'working' Python code, TCP_Barcode_V1.py which read a text file and gives output in a tkinter window.

However, if I convert the Python file to an .exe using auto-py-to-exe, when executing TCP_Barcode_V1.exe, am getting error like fatal error occurred Failed to execute script TCP_Barcode_V1 in a messagebox

error

my text file, param.txt looks like this :

192.1.22.43
6666
3000

each line is read and stored in a variable

In my python file, am reading the file as

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
my_file = os.path.join(THIS_FOLDER, 'param.txt')

with open(my_file, "r") as fp:
  val = [line.strip() for line in fp]


duration = int(val[0])
TCP_IP = val[1]
TCP_PORT = int(val[2])

Can someone identify what the problem here is.

Please note that the original TCP_Barcode_V1.py is working without any issues. And also, I am using the same device for running the .py as well as .exe file.

below is my auto-py-to-exe settings I chose

AutoPy

Sid133
  • 354
  • 2
  • 17
  • Can you run it with --debug flag? – Saatvik Ramani Jun 20 '21 at 07:01
  • @SaatvikRamani : Its showing file not found error but its looking at a different path. "..\\Appdata\\Local\\Temp\\_MEI78002\\param.txt. _MEI78002 is a temp folder, it changes everytime I run the application – Sid133 Jun 20 '21 at 09:28
  • You can specify the resources your executable needs using the `--add-data` flag. `pyinstaller --add-data "" --noconfirm --onefile --windowed ""` You can also specify multiple files separated by a `;`. – Saatvik Ramani Jun 20 '21 at 13:52
  • Ok, what if I have to move the exe along with the text file to a different location? Does that mean I have to reconfigure the exe again? – Sid133 Jun 20 '21 at 13:57
  • Ideally, it should be in the same directory as your python files and hence is wrapped into your executable. – Saatvik Ramani Jun 20 '21 at 16:07

0 Answers0