Home > Software design >  Python Executable not Running in Terminal
Python Executable not Running in Terminal

Time:11-02

I created a python script in VS Code that runs perfectly fine.

I am trying to turn it into an executable for ease of access and use.

I have a macbook air m1 and everything should be up to date.

I installed pyinstaller with pip install pyinstaller.

When I run pyinstall #filename I get everything to run fine including the python executable inside the folder.

I have also tried pyinstaller --windowed #filename and it works fine as well according to the stuff that pops up.

When I run the executable my terminal opens for half a second and spews something and then it dissapears. When I check my taskbar I see terminal still open so I click on it. it shows just a blank terminal and I cannot scroll up to see what was running before hand.

I am not sure what I am doing wrong that is causing the exe to not run but when I run python3 #filename in the terminal everything runs fine.

Any help would be appreciated

I have tried not a whole lot because I am not sure what the error really is

I expect that when I run the python exe that was created I will get the terminal opening up and the first lines of my code asking for user input will run.

instead I get the terminal opening up and getting some gibberish I do not have time to read and then the terminal blanks out and I cannot see what it did.

CodePudding user response:

This is 5 step the process that i use (which works for windows):

Can you verify that steps 1 & 2 are done correctly ? And also that you have done the ios version of the windows commands.,,

  1. Add Python to Windows Path: An easy way to add Python to the path is by downloading a recent version of Python, and then checking the box to 'Add Python to PATH' at the beginning of the installation.

  2. Install the PyInstaller Package:

pip install pyinstaller
  1. create a script: Here is an example.
import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()

def hello ():  
    label1 = tk.Label(root, text= 'Hello World!', fg='blue', font=('helvetica', 12, 'bold'))
    canvas1.create_window(150, 200, window=label1)
    
button1 = tk.Button(text='Click Me', command=hello, bg='brown',fg='white')
canvas1.create_window(150, 150, window=button1)

root.mainloop()
  1. Create the Executable using PyInstaller: go to the Command Prompt and type: cd followed by the location where your Python script is stored.

    then type: pyinstaller --onefile pythonScriptName.py

  2. Your executable will be created at the location that you specified: There will be a subfolder called dist and the executable will be there.

CodePudding user response:

for my personal reference I use Anaconda Jupyter notebook for developing. Then I usually save the jupyter notebook where the code resides as a python script as .py. After that I can use this executable python script into anything as I need. run is from task scheduler, I can run it manually, from the shell, or anything based on the scenario

  • Related