Python-- The project is packaged as python exe

1. pyinstaller package

  • Official website Link:  https://pyinstaller.readthedocs.io/en/stable/
  • 安装: pip install pyinstaller
  • Packaging step
    • Python into the project directory, find the path where main.py (entry point)
    • Execute the command: pyinstaller -F main.py (there are many other parameters, can choose)
    • You will find the current directory will be more dist, build, dist directory is packaged exe after successful package
    • Verification: execute exe, to see if success

 

2. pyinstaller pack a big problem to solve

Cause: The python environment using the full package will contain a lot of other not to use the package, so in the end to break out of the package is very big, most of them more than 50m

Solution: You can create a python virtual environment, only add their own projects to use the python package, it can greatly reduce the generated package

pipenv

  • pip Install pipenv(安装pipenv)
  • pipenv shell (activation pipenv, after the execution is complete, means you have entered the new virtual environment is no longer a complete python environment, authentication method, you can execute this command before and after, respectively, performed twice pip list, view the installation packages virtual environment package will be a lot less)
  • pipenv install (package installed in the virtual environment will be used to)
  • pipenv install pyinstaller (need to install python packaging tools in a virtual environment, it can be packaged)
  • pyinstaller -F <python project> of the virtual environment package

tips: The above command is a continuous step, beginning when I use do not know how to use the virtual environment to package, only to find themselves ignored pipenv shell that means you have entered the virtual environment, so this time again the installation or packaged, in fact, based on what the new virtual environment.

   Use pipenv break out of the pack will be greatly reduced, if you found before you pack and pack, exe's size is as big, it is certainly not used to the virtual environment.

Guess you like

Origin www.cnblogs.com/emmaduan/p/11725838.html