Before I tried to use pipenv to manage virtual environment, and use pipenv to create virtual environment to package exe.
Use pipenv to create virtual environment to solve the problem of python packaging exe file is too large (with packaging icon, multiple py files packaging exe)
Pipenv creates a virtual environment. It is difficult to change the pyhon version. The default python is the python that comes with the computer.
The virtual environment created by anaconda can change the python version.
When using the virtual environment to package the exe, if some deep learning frameworks are included, the required deep learning framework version is generally very low, and the deep learning framework version is low, and the matching python version is also low. At this time, it will be more troublesome to use pipenv again. (Because maybe our computer comes with a very high version of Python)
See the link for the correspondence between the deep learning framework and python.
The correspondence between the versions of the python deep learning environment support list, Keras, TensorFlow, pytorch, caffe, etc.
Anaconda common commands
#Get version number conda --version or conda -V #Check and update the
current conda
conda update conda #Check
which virtual environments currently exist
conda env list or conda info -e #View
– install – update – delete package
conda list:
conda search package_name # Query package
conda install package_name
conda install package_name=2.6.0
conda update package_name
conda remove package_name
anaconda virtual environment
Create a virtual environment
conda create -n your_env_name python=X.X(2.7、3.6等)
Activate the virtual environment
#Linux
source activate your_env_name
#Windows
activate your_env_name
Delete virtual environment
conda remove -n your_env_name --all
conda remove --name your_env_name --all
anaconda virtual environment packaging
Use conda create -n your_env_name python=XX (2.7, 3.6, etc.), anaconda command to create a virtual environment with python version XX and name your_env_name. The your_env_name file can be found under the envs file in the Anaconda installation directory.
The first step: the original folder, enter cmd and
note that anaconda python has been added to the environment variable.
If not, check the link
cmd to execute the python program, and the folder directly enters the cmd program
Step 2: Create an environment for specifying the python version
conda create -n yudengwu python=3.6
Click y to automatically install the necessary packages
End of installation
Step 3: Activate the virtual environment
#Linux
source activate your_env_name
#Windows
activate your_env_name
Step 4: Install the packaged exe and program-related libraries
Pyinstaller required for packaging
pip install pyinstaller
Install related libraries such as
pip install opencv-python
Step 5: View installed libraries
conda list
Step 6: Pack the exe
here, simply pack it, and see the pipenv version of the link for more packing.
pyinstaller -F xx.py
Can run
More
The following error message appeared when using pipenv to package tensorflow before
ImportError: DLL load failed of tensorflow: The initialization routine of the dynamic link library (DLL) failed
The reason for this error is that the recent tensorflow installation package does not support older processors, and the old version of tensorflow needs to be installed
. At that time, the python version corresponding to pipenv was 3.7. The python version of 3.7 corresponds to tensorflow not low.
The python version specified in the virtual environment created by anaconda this time is 3.6. Let me try to see if it can be used after installing tensorflow.
Install a low version of tensorflow in a virtual environment
pip install --ignore-installed --upgrade tensorflow==1.5
Version 1.5 is fine. When I use version 1.11.0, mportError: DLL load failed: The initialization routine of the dynamic link library (DLL) failed.
It seems that the appropriate version is 1.5 and below
Regardless of python3.6, TensorFlow1.5 can be used in a virtual environment
After installation, test it:
first enter python and
enter python, and then test
Success means that we can package the deep learning model into an exe.
The new computer in electrical engineering: Yu Dengwu. If you think this article is good for you. Please give a thumbs up and support, thank you.