In the post, I’ll show you how to build a simple interactive app using python and make it executable under all major operating systems.
First, Let’s see what the app can do.https://www.zhihu.com/video/1160081743259512832
From the video, we can see that the app takes in your name and your hobby, and then return your basic description.
Now, let’s build this simple app from scratch.
Step 1 - create a new conda environment
It’s always a good hobby to create a separate environment for your project.
conda create --name app
conda activate app
Step 2 - install required packages
Since this project is very basic, we only need to install Pyinstaller
pip install pyinstaller
Note that For Windows, PyWin32 or the more recent pypiwin32, is a prerequisite. The latter is installed automatically when you install PyInstaller using pip or easy_install. If necessary, follow the pypiwin32 link to install it manually.
Step 3 - write the script
in app.py script
# get the name of the user
print("\n22:First, please tell me your name : ) ")
name = input("Me:My name is:")
# get the hobbies of the user
print("\n22:Oh, I see. And your hobbies are? ")
hobbies = input("Me:My hobbies are:")
# give result
print("\n22:haha, I got you! ")
print("22:your name is ", name, "and your hobbis are", hobbies,"\n")
Step 4 - make the python file executable
in the terminal under the same directory as app.py
pyinstaller --onefile app.py
Step 5 - find the executable file under the dist directory
The pyinstaller will automically create multiple files, just double click the executable app file under dist directory, and then you can play with it and send it to your friends!
Now, you can play with your new app! Isn’t that so simple?
NOTE:
If you use pyinstalled under mac or linux system, then the file can be run in linux system, but not in windows.
If you pyinstalled the script under windows, then it can be run in windows, but not in linux.
请关注我的微信公众号 2加2加2~ 谢谢~