Python Project Management __python

Source: Internet
Author: User
Tags python script

Virtual Environments
First, Python does not seem to have a project management tool like Maven/ant. What happens when there are multiple Python projects on a machine, and these Python projects have different dependencies and don't want to interfere with each other?
The official practice is to isolate each project from each other using virtual environments. In general, we use the Python interpreter to run a Python script or module:

>python myscript.py

The directory that is running is the Python interpreter that is installed, that is, the directory where Python.exe resides. Virtual environments is a unique directory for each project that contains the Python interpreter, the Python standard class library, and various other necessary files. This allows each project to use a different interpreter and class library, without interfering with each other.
The creation process is also simple. First find the directory where pyvenv.py is located, usually under the directory \tools\scripts of the installation directory. This is a tool to generate virtual environments. And then run:

>pyvenv tutorial-env

A directory named "Tutorial-env" is generated when it is run. Finding this directory, you can see that this directory contains all the files necessary to run the Python project, as stated on the website. Use the interpreter contained in the respective virtual environments directory to run a specific Python project. Also, the specific dependencies (packages or module) used for each project are added to the class Kuzi directory of the respective virtual Environments directory. Here's what you need to be aware of. After you create the virtual environments, you also need to activate it. The procedure is simple, in the example tutorial-env directory under the execution of the command can be:

>tutorial-env/scripts/activate

PIP
The PIP is an official tool for installing the Python Third Party Class library (Packages/module). It can go to PPI (Python packages index) to find or download a Third-party class library. URL is: Https://pypi.python.org/pypi
Locate the Pip.exe in the above example virtual Environments directory and run:

>pip Install Lib_name

Can be installed, other features please check the manual yourself. If you run the PIP under the Python installation directory, the class library can be used by all projects that are not virtual environments. The PIP is actually installed package.

Requirements.txt
Run under Virtual Environments directory:

>pip Freeze > Requirements.txt

You can produce a list file of all the dependent class libraries and their versions of the current project, and the filename is requirements.txt (you can also use a different name, of course). The contents of the document are roughly as follows:

novas==3.1.1.3
numpy==1.9.2
requests==2.7.0

The benefits of using Requirements.txt are:
The requirements.txt can then is committed to version control and shipped as part of the application. Users can then install the necessary packages with "Install-r":

>pip Install-r Requirements.txt

This makes it easy to manage project dependencies. If you do not use Requirements.txt and use version control to store the virtual environments directory directly, other programmers can download the directory directly to start the practice of project development.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.