Use virtualenv to package python programs

1. Install the module

pip install virtualenv virtualenvwrapper-win

2. Configure the virtual environment

First configure the virtual environment installation directory, and the newly created virtual environment will be in this directory, otherwise it will be created in the c drive

After configuring the environment variables, reopen cmd

#列出虚拟环境列表
workon
#新建虚拟环境:
mkvirtualenv 虚拟环境名称
#启动/切换虚拟环境:
workon 虚拟环境名称
#离开虚拟环境
deactivate

As follows, create a new virtual environment named ms and activate it automatically

It includes a dedicated Python interpreter and a set of dependencies. Executing the script in a virtual environment ensures that the script uses the Python interpreter and dependencies in the virtual environment and avoids conflicts with the Python interpreter and dependencies in the global environment.

3. Enter the \virtual environment\Scripts directory, and download the package used in the python file to be packaged

The downloaded package will be placed in the "virtual environment\Lib\site-packages\downloaded package" directory

4. At the same time, put the python file to be packaged in the Scripts directory and package it.

It should be noted that the virtual environment is mainly used to isolate the Python environment and dependencies to ensure the independence and portability of the project, and does not necessarily reduce the size of the executable file significantly

Guess you like

Origin blog.csdn.net/qq_44159028/article/details/131106209