[Gobang Actual Combat] Chapter 4 Deploy Gobang Computing Interface to Window and Linux
In the previous chapter, we developed a backgammon calculation interface with python, and it can be run on our own computer. However, there are several problems that follow:
1. I want to send the game to my friend's computer to play, but his computer does not have a python operating environment, so how can he run the interface file? You can't let him install a python.
2. I want to publish the game on the Internet, usually on the Linux platform, what should I do?
The issues involved in the above two scenarios are:The python project is packaged into an exe executable file;Python's Flask interface deployment。
The python project is packaged into an exe executable file
## Step 1. Install pyinsatller
Open the command line window and enter the following command
pip3 install pyinstalle
Wait for the pyinsatller library to be installed.
## Step 2, use pyinstaller to package the Python program
1. Select the upper-level directory of the py file you want to package, hold down shift and right-click, and click "Open command line window here" or "Open PowerShell window here" in the pop-up options.
2. Enter the following command to start packaging
pyinstaller -F -w (-i icofile) filename
· filename means the py file name
· -w means to hide the command line window when the program is running (there will be a black window without adding -w)
· The parameters in brackets are optional parameters, -i icofile means to add an icon to the program, and the icon must be .ico format
· icofile indicates the location of the icon, it is recommended to put it directly in the program folder, so that it is good to write the file name directly when packaging. After the input is
complete, press Enter, and the packaging will start automatically. The first packaging process may be slow
## Operation Demo
1. There needs to be a main py file in the project, which I named as main.py
. main.py
It is an open interface of flask.
2. Then I press "shift" + right click on the project folder ( main.py
upper level), and click "Open PowerShell window here".
3. Enter the statement to start packaging main.py
.
pyinstaller -F -w main.py
4. The packaging is complete, and it is generated in the dist folder main.exe
.
The final generated file main.exe can be run by double-clicking.
In this way, our interface can be run even on a computer without a python operating environment.
## Precautions! !
· When importing library files, keep them as small as possible. Use from xxx import xxx. In this way, when packaging, the library files it extracts will not be redundant, and the entire packaged project will be smaller.
· The imported exe is in the dist folder and cannot be moved. It needs to use library files in other folders.
Python's Flask interface deployment (Linux)
## Step 1. Install the necessary software dependencies
Make sure our Linux system has Python and pip (Python package manager) installed. If it is not installed, it needs to be installed using the package manager for our Linux distribution. For example for Ubuntu, it can be installed with:
sudo apt update
sudo apt install python3 python3-pip
## Step 2. Install Flask and other dependencies
Install the libraries needed in our project:
pip install flask numpy
## Step 3, run flask
In a terminal, run the Flask application on the server with the following command:
python app.py
If your application listens on a port other than the default port 80, you can use the --port option to specify the port number.
python app.py --port 5000
## Step 4, configure the server
After deployment, it is also necessary to configure the server to interface with the Flask application. A web server such as Nginx or Apache can be used to proxy requests to the Flask application. The specific configuration depends on the server software you use and the location of the configuration files. It is recommended to use nginx, which is very light and easy to operate.
Continue to learn the next actual combat!
[Gobang Actual Combat] Chapter 5 Developing Gobang Front-End Pages