In KDE, open the main menu and select "Run Command." to open Konsole. Create a folder on your computer to use for your Python programs, such as ~/pythonpractice, and save your hello.py program in that folder.If you have both Python 2 and Python 3 installed (Your machine comes with a version of Python 2 but you can install Python 3 as well), you should run python3 hello.py Type cd pythonpractice to change directory to your pythonpractice folder, and hit Enter.Open the Applications folder, go into the Utilities folder, and open the Terminal program. A good suggestion would be to name it pythonpractice and place it in your Home folder (the one that contains folders for Documents, Movies, Music, Pictures, etc). Create a folder on your computer to use for your Python programs.If it didn't work, make sure your PATH contains the python directory. Type cd \pythonpractice to change directory to your pythonpractice folder, and hit Enter.This will cause the Windows terminal to open. In the Start menu, select "Run.", and type in cmd.Create a folder on your computer to use for your Python programs, such as C:\pythonpractice, and save your hello.py program in that folder.Now that you've written your first program, let's run it in Python! This process differs slightly depending on your operating system. Using print with parentheses (as above) is compatible with Python 2.x and using this style ensures version-independence. In Python 3.x, print is a proper function expecting its arguments inside parentheses. As such, it can be used without parentheses, in which case it prints everything until the end of the line and accepts a standalone comma after the final item on the line to indicate a multi-line statement. In Python 2.x, print is a statement rather than a function. ![]() By default, print appends a newline character to its output, which simply moves the cursor to the next line. Now head back to the “dist” folder, and we have a beautiful and professional looking Python app that can be run almost on any computer, with or without Python installed.This program uses the print function, which simply outputs its parameters to the terminal. To add an icon to our app, use the -icon argument.To freeze Python code into a single file, use the -onefile argument.Conveniently, pyinstaller provides some really cool command line input arguments we can play with. However, the folder still contains tons of files and it could be confusing for others which file to run. Freeze Python App Exampleĭouble click to run the app, you will see that the app just generated an Excel file named “spend_by_category.xlsx” in your working directory.Įverything we need to run the app is within the “dist” folder so we can delete other extra folders and files, and we can just send the dist folder to another person and they’ll be able to run our Python app. “freeze_eg.py” is the script that you want to freeze, so you have to change it to whatever your file name is.Īfter a moment when the freezing is done, you will see several new folders in your working directory, go into “dist” folder and find the application file with the same name as the script, in my case “freeze_eg”. In the command prompt window, type pyinstaller freeze_eg.py. The output is a dataframe with only 14 rows and 2 columns. ![]() The data source is a mocked-up credit card statement with 533 transactions throughout year 2020. We basically try to analyze our credit card statement and generate a summary table with total and average spending for each category. Spend_category.to_excel(r'E:\PythonInOffice\freeze_python_code\spend_by_category.xlsx') Spend_category = df.groupby('Category').agg(Total_spend=('Debit','sum'), I want to focus on the pyinstaller so we’ll recycle the previous groupby example with the following code: import pandas as pdĭf = pd.read_csv(r'E:\PythonInOffice\freeze_python_code\cc_statement.csv', parse_dates=)ĭf = pd.to_datetime(df)ĭf = df.dt.day_name()ĭf = df.dt.month Let’s recycle a previous example… yes I’m lazy ? If you are using an earlier version of Python, I highly recommend you upgrade to at least 3.8 and it’s also for your benefit. ![]() Note that the latest pyinstaller is compatible with Python 3.6-3.9, which are more recent versions. We’ll need to download pyinstaller via pip: pip install pyinstaller Then it collects copies of all those files – including the active Python interpreter! – and puts them with your script in a single folder, or optionally in a single executable file. It analyzes your code to discover every other module and library your script needs in order to execute. PyInstaller reads a Python script written by you. Pyinstaller is a Python library that can freeze Python scripts for you and it’s very easy to use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |