Python freeze
Python applications use a variety of packages in development, and typically we use venv to isolate the Python interpreter versions and their packages that are dependent on each application project.
How can the various packages of import in the app be "pinned"? Pip provides method freeze, the dependent package name and version exported to the TXT file, in the future when others introduced the project, can be directly imported through the method provided by the PIP, simply speaking:
Pip Freeze > Requirements.txtpip install-r requirements.txt
Similar to the Java MAVEN Warehouse import, the more lightweight and environmentally friendly.
Virtual env
In the use of Java applications, we will specify the JDK path for the project. In most cases, there may be 1-3 versions of the JDK on each development machine, such as Jdk6, Jdk7, JDK8, which is usually enough. The java_home path is then specified in the system path variable.
Dependencies on external third-party packages for Java applications are set by Maven and are brought into the app's directory as a dependency on build.
Python has a slightly different control style, since Python itself has the package management tool with PIP. And because Python is a dynamic scripting language, there may be several different sets of scripts distributed across different directory organizations, and because of the development cycle, the scripting of each directory depends on the Python interpreter, and the package may be different, A good script running in Python2 the interpreter for Python3 usually goes wrong.
We need a way to isolate the various sets of scripts in the environment, which is solved with virtual env.
The exact way is in the root directory of the Python project:
|-mypythonproject | ——— codepackage
Run:
Virtualenv-p Python3 Env-p represents the creation of a PYTHON3 virtual environment
env represents the directory of the virtual environment called ENV
The directory structure after running is:
|-mypythonproject | ——— codepackage | ——— env |--bin |--lib |--include
Then we need to activate this virtual environment:
SOURCE Env/bin/activate
After activation, the environment prompt changes to:
(env) ➜knife git: (master) ✗
Indicates that the environment is already the virtual Python3 environment required for this project, and all the package of PIP install will be installed in the Env/lib/python3.5/site-packages directory at this time. Will not be affected by package packages installed by other Python projects.
If you are using Ides such as pycharm, you need to specify project interpreter for your projects when you create them, such as: