There are many excellent packages in Python. This article mainly talks about pip, virtualenv, fabric
1. pip is used for package management
Documentation: https://pip.pypa.io/en/latest/installing.html
# Installation, you can specify the version number
(sudo) pip install Django==1.6.8
# Upgrade
(sudo) pip install bpython --upgrade
# Install multiple at one time
(sudo) pip install BeautifulSoup4 fabric virtualenv
# Install from the text, the text is the package name, one per line, you can specify the version number
(sudo) pip install –r requirements.txt
# Delete
(sudo) pip uninstall xlrd
# Export the currently installed package
pip freeze > requirements.txt
2. virtualenv independent Python environment management
Documentation: http://virtualenvwrapper .readthedocs.org/en/latest/
virtualenv is a package that creates a Python independent environment. virtualenvwrapper makes virtualenv easier to use
# Installation:
(sudo) pip install virtualenv virtualenvwrapper
# Modify .bash_profile and add the following statement
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/YunPan/workspace
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv ENV: Create a running environment ENV
rmvirtualenv ENV: Delete a running environment ENV
mkproject mic: Create a mic project and running environment mic
mktmpenv: Create a temporary running environment
workon bsp: Work in the bsp running environment
lsvirtualenv: Column List the available running environments
lssitepackages: List the packages installed in the current environment
The created environment is independent and does not interfere with each other. You can use pip to manage packages without sudo permissions.
The following is a usage demonstration diagram:
3. Fabric server management and application release
Official website: http://www.fabfile.org/
Documentation: http://docs.fabfile.org/
fabric: application deployment or systems administration tasks
#coding:utf-8
from fabric.api import *
# Server list
env.hosts = ['user@server1' ,'user2@server2']
def ls_home():
with cd('/home/bae/'):
run('ls')
'''
Commonly used Command
lcd(dir): Enter a directory on the local machine
local(cmd): Execute the command on the local machine
cd(dir): Enter a directory on the server
run(cmd): Execute the command on the server
''
Save the above file as fabfile.py Enter the directory of the file on the terminal and execute
fab function name
For example:
fab ls_home
Please refer to the official documentation for more usage methods.