Python program packaging under Windows&Ubuntu

        The Python program must have a Python environment to run, but the program is compiled for use. What if it is used by someone else, and his/her computer does not have a Python program running environment? Can't let him/her install one? At this time, we need to package the Python program into an exe executable file, so that under the Windows/Linux (corresponding platforms are packaged separately) platform, the program can be run directly, regardless of whether there is a Python environment or not .

        Written in front: This article mainly records the packaging of python programs. In fact, the packaging process under windows and ubuntu is basically the same, but when I packaged the same program in ubuntu, I found that it is best to open a virtual environment for packaging.

        Development IDE: Pycharm 2022.3.2 professional, Anaconda.

1. Package exe

1. Create a virtual environment

        In the Interpreter in the lower right corner of Pycharm, select Add New Interpreter, select to create a new virtual environment, and check Inherit global site-packages at the same time, so that a base environment is copied, which can avoid repeated installation of packages.

2. Open the terminal of pycharm and enter the following command to install the Pyinstaller module.

pip install Pyinstaller

 3. Perform exe packaging

        Executes the function of the Pyinstaller module.

Pyinstaller -F 文件名.py

        Packaged successfully.

 4. View the packaged exe

 2. Problems encountered

        The 'pathlib' package is an obsolete backport of a standard library package.....

conda remove pathlib

        But look at the command after running. When I encountered this problem on ubuntu, I executed this command and asked whether to uninstall many packages in the original environment , but Windows did not encounter it. No relevant explanation was found. Finally, my situation on ubuntu is to create a virtual environment after installing Pyinstaller, execute conda remove pathlib update, and re-pip install the packages needed in the program, which is troublesome (may also involve changing sources, etc.).

Guess you like

Origin blog.csdn.net/weixin_44855366/article/details/130167017