The venv of the Python environment

Source: Internet
Author: User
Tags i18n serialization virtual environment virtualenv

Demand

We use anisible to manage OpenStack at this point we need to install the shade module when there is an Internet we can install the shade module in the following ways

Yum Install Python-pippip Install shade

However, the company does not have the Internet environment and the use of shade this module, then thought to execute pip install shade see what packages and then made a separate source, but no fruit. Later I thought pip download shade and then installed shade offline. But the good trouble finally found virtualenv.

First of all, talk about what virtualenv is.

Virtualenv The idea of a virtual environment for Python to provide an "isolated" environment such as the operating system level requires the use of Python2 and python3 at this time if the system is set environment variables will be inconvenient to affect the system Python environment independence. Of course, Python naturally supports several modules we can install these modules at the system level, but if we change a development environment, we need to reinstall these modules. If we use virtualenv and install these packages in the VIRTUALENV environment, we can directly pack the directory and go directly to use. Let's see how the Virtualenv is used.

1. Install Pip and virtualenv

[email protected] ~]# Yum install python-virtualenv Python-pip

2. Create a project of your own

[Email protected] erick]# virtualenv-p/usr/bin/python2 venvalready using interpreter/usr/bin/python2new python execut Able In/root/erick/venv/bin/python2also Creating executable in/root/erick/venv/bin/pythoninstalling Setuptools, Pip, Wheel...done.

3, into the current environment "after the execution can see more than one (venv)"

[Email protected] erick]# source Venv/bin/activate (venv) [[email protected] erick]#

4, good at this time you can install the required modules in our own projects than I want to install the shade module I need

(venv)  [[email protected] erick]# pip install shade ... Omit collecting pyperclip  (from cmd2>=0.6.7->cliff>=2.6.0->osc-lib>=1.5.1-> Python-ironicclient>=1.11.0->shade) installing collected packages: six, munch,  netifaces, funcsigs, pytz, babel, pbr, oslo.i18n, monotonic, netaddr,  pyparsing, wrapt, debtcollector, iso8601, oslo.utils, pyyaml, rfc3986,  stevedore, oslo.config, chardet, certifi, idna, urllib3, requests,  Positional, keystoneauth1, msgpack-python, oslo.serialization, python-keystoneclient,  dogpile.cache, jsonpointer, jsonpatch, requestsexceptions, decorator, appdirs,  os-client-config, jmespath, futures, functools32, jsonschema, unicodecsv,  Prettytable, pyperclip, cmd2, cliff, simplejson, osc-lib, deprecation, openstacksdk, python-novaclient, warlock,  python-glanceclient, python-cinderclient, python-openstackclient, python-ironicclient,  ipaddress, shadesuccessfully installed babel-2.3.4 prettytable-0.7.2 pyyaml-3.12  appdirs-1.4.3 certifi-2017.4.17 chardet-3.0.4 cliff-2.8.0 cmd2-0.7.5  debtcollector-1.16.0 decorator-4.1.1 deprecation-1.0.1 dogpile.cache-0.6.4 funcsigs-1.0.2  functools32-3.2.3-2 futures-3.1.1 idna-2.5 ipaddress-1.0.18 iso8601-0.1.11  jmespath-0.9.3 jsonpatch-1.16 jsonpointer-1.10 jsonschema-2.6.0 keystoneauth1-2.21.0  monotonic-1.3 msgpack-python-0.4.8 munch-2.1.1 netaddr-0.7.19 netifaces-0.10.6  openstacksdk-0.9.17 os-client-config-1.28.0 osc-lib-1.7.0 oslo.config-4.8.0  Oslo.i18n-3.16.0 oslo.serialization-2.19.1 oslo.utils-3.27.0 pbr-3.1.1 positional-1.1.1 pyparsing-2.2.0 pyperclip-1.5.27  python-cinderclient-2.2.0 python-glanceclient-2.7.0 python-ironicclient-1.14.0  python-keystoneclient-3.12.0 python-novaclient-9.0.1 python-openstackclient-3.11.0 pytz-2017.2  requests-2.18.1 requestsexceptions-1.3.0 rfc3986-1.0.0 shade-1.22.2  simplejson-3.11.1 six-1.10.0 stevedore-1.24.0 unicodecsv-0.14.1 urllib3-1.21.1  warlock-1.2.0 wrapt-1.10.10 (venv)  [[email protected] erick]#

You can see that at this point the Shade module has been successfully installed, yum install python-devel reference link is https://stackoverflow.com/questions/21530577/ Fatal-error-python-h-no-such-file-or-directory

5. Jogen Ansible Use the project we just made to add ansible_python_interpreter= "your dir" to your asset list for example

[controller]192.168.1.100 ansible_python_interpreter= "/root/erick/venv/bin/python"

It's ready to pack and take.

We're here to install a tornado module.

(venv)  [[email protected] erick]# pip install tornadocollecting tornado   Downloading tornado-4.5.1.tar.gz  (483kB)     100% | ████████████████████████████████| 491kb 28kb/s collecting backports.ssl_match_hostname   (From tornado)   downloading backports.ssl_match_hostname-3.5.0.1.tar.gzcollecting  singledispatch  (From tornado)   Downloading  singledispatch-3.4.0.3-py2.py3-none-any.whlrequirement already satisfied: certifi in  ./venv/lib/python2.7/site-packages  (From tornado) collecting backports_abc>=0.4  (from  tornado)   downloading backports_abc-0.5-py2.py3-none-any.whlrequirement already  satisfied: six in ./venv/lib/python2.7/site-packages  (from singledispatch-> Tornado) Building wheels for collected packages: tornadO, backports.ssl-match-hostname  running setup.py bdist_wheel for tornado  ... done  stored in directory: /root/.cache/pip/wheels/84/83/cd/ 6a04602633457269d161344755e6766d24307189b7a67ff4b7  running setup.py bdist_wheel for  backports.ssl-match-hostname ... done  stored in directory: /root/. cache/pip/wheels/5d/72/36/b2a31507b613967b728edc33378a5ff2ada0f62855b93c5ae1successfully built  tornado backports.ssl-match-hostnameinstalling collected packages:  Backports.ssl-match-hostname, singledispatch, backports-abc, tornadosuccessfully installed  backports-abc-0.5 backports.ssl-match-hostname-3.5.0.1 singledispatch-3.4.0.3  tornado-4.5.1 (venv)  [[email protected] erick]#

Finally, let's see where we can put the module.

(venv) [Email protected] site-packages]# pwd/root/erick/venv/lib/python2.7/site-packages (venv) [email protected] site-packages]# ls-d Shade Tornado Shade Tornado

In short, what you need to pack can be packaged and taken away. It's the same as eating in a restaurant.


Reference links

Https://help.dreamhost.com/hc/en-us/articles/218925908-How-to-launch-a-DreamCompute-server-with-Ansible


http://docs.python-guide.org/en/latest/dev/virtualenvs/


This article is from "Perfect world!" "Blog, be sure to keep this provenance http://shyln.blog.51cto.com/6890594/1947956

The venv of the Python environment

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.