Use virtualenv to isolate Pyhon, ansible different distributions

Source: Internet
Author: User
Tags virtual environment virtualenv
1.virtualenv Introduction

In Python development, we might encounter a situation where the current project relies on a particular version, but another project relies on another version, which creates a dependency conflict, and virtualenv is the solution Virtualenv by creating a virtualized Python runtime environment, the dependencies we need are installed, and the different projects don't interfere with each other, as shown below.
2. Install virtualenv

The first thing to do is to install the necessary dependencies, or the subsequent error

Yum Install Python-setuptools Python-setuptools-devel

Installation virtualenv is simpler, and can be installed on both Linux and Windows via the pip , as follows: Pip install Virtualenv

if the installation is unsuccessful, you can download the VIRTUALENV source package and install Virtualenv by performing setup.py. At the same time because of the difference between Python2 and Python3, there are two kinds of PIP and pip3 two kinds of Python package installation tools, and the virtualenv of the two tools are different. The Virtualenv virtualized Python runtime environment that Py2 installs is Python2, Py3 installed virtualenv default virtualization environment is Python3. 3.virtualenv Run use 3.1 to create a virtualized environment

Using Pycharm as the editor for this example, select python2.7 work Environment, create a new project Virtualenvdemo, and enter a command in the console:

Virtualenv venv

The Venv folder is created in the current project, and the virtual Python runtime environment for the current project is as follows:

I am here. The default Python environment is python2.7, and the virtual environment created at this time is a virtualized environment created with python2.7, and if you need to select a Python interpreter to create a virtualized environment, the command is:

Virtualenv-p/usr/bin/python2.7 venv

At this point, you need to change the current project interpreter to the current virtual environment, otherwise it will not work, this is no longer detailed.


3.2 Enable

The commands for activating a virtualized environment are:

SOURCE Venv/bin/activate

After activation, there will be a (VENV) flag in the console, as follows:
3.3 installation dependencies

after the above is done, you can install the Python package by using the command pip install, where the Python package is installed without root permission, which can be easily installed directly. In a venv environment, packages that are installed with PIP are no longer global packages and will only work in the current virtual environment to avoid polluting the system environment. 3.4 Exiting the current system environment

When you enter a command deactivate in the console, the current VENV virtualization environment is rolled out.

(. virtualenv) # Deactivate

# exit 4.virtualenv Other Commands

Virtualenv Various other orders are as follows:

"'
Usage:

$ virtualenv [options] dest_dir
Options:
–version
Displays the current version number.
-h,–help
Displays help information.
-v,–verbose
Displays detailed information.
-q,–quiet
does not display detailed information.
-P Python_exe,–python=python_exe
Specifies the version of the PYTHON parser used, such as –python=python2.5 to create a new isolation environment using the 2.5 version of the parser. The default is to use the Python parser
–clear
for the current system installation (/usr/bin/python) to empty the non-root installation and create an isolated environment from scratch.
–no-site-packages
makes the isolated environment inaccessible to the system global Site-packages directory.
–system-site-packages
Enables an isolated environment to access the system global Site-packages directory. Extract setuptools or Distribute
–relocatable
during installation of
–unzip-setuptools
to reposition an existing isolated environment. Use this option to correct the script and to use a considerable path for all. pth files.
–distribute
replaces setuptools with distribute, and you can set environment variables Virtualenv_distribute achieve the same effect.
–extra-search-dir=search_dirs
is used to find directories for SETUPTOOLS/DISTRIBUTE/PIP publishing packages. You can add any number of –extra-search-dir paths.
–never-download
prohibits downloading any data from the Web. At this point, the virtualenv will complain if the publish package has failed to be searched locally.
–prompt==prompt
Defines the command line prefix for an isolated environment.
'
5. Fully

Virtualenv is a virtualized Python environment that facilitates the development and operation of different projects on the same machine.

Virtualenv is more suitable for local development of different projects, but in the production environment or use Docker to different projects to create different containers, separate run as well, should not be placed in a separate physical machine to run.

6. Install the necessary ansible dependency pack

# pip Install Paramiko Pyyaml jinja2

# CD Ansible

# git submodule update--init lib/ansible/modules/core

# git submodule update--init Lib/ansible/modules/extras

7. Loading ansible2.1

Tip:env-setup is a script prepared by Ansible for hacker to set some of the environment variables that are required for ansible

# . /home/deploy/.virtualenv/ansible/hacking/env-setup-q

$ ansible--version

  ansible 2.1.0 (devel 6ddea3e915) Last updated 2016/02/16 16:13:32 (GMT +800) lib/an Sible/modules/core: (detached head 8d126bd877) Last updated 2016/02/16 16:19:09 (GMT +800) Lib/ansible/modules/extras: ( Detached head f6c5ed987f) Last updated 2016/02/16 16:19:40 (GMT +800) config file =/etc/ansible/ansible.cfg Configure D Module Search Path = Default w/o overrides  

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.