DEV Community

Cover image for Python tools
Python64
Python64

Posted on

Python tools

In this article we'll discuss some python tools, these will make your development easier. Namely:

  • the python package manager pip
  • virtual environment
  • remote ssh.

Pip for package management

Python has many available packages or modules. These are existing code bases you can use to accelerate development. This is similar to libraries in C/C++.

To install module you need pip. To install pip, see this article.

For module installation, you can specify a version number

(sudo) pip install Django == 1.6.8

Upgrade package

(sudo) pip install bpython --upgrade

Install multiple packages

(sudo) pip install BeautifulSoup4 fabric virtualenv

Installation from the text, the text for the package name, one per line, you can specify a version number

(sudo) pip install -r requirements.txt

Delete a module

(sudo) pip uninstall xlrd

Export the currently installed package

pip freeze> requirements.txt

Virtualenv independent Python environmental management

virtualenv is a Python package to create a separate environment. Using virtualenv you won't have any module conflicts (as you may get when installing with sudo).

    # Installation:
    (sudo) pip install virtualenv virtualenvwrapper
    
    # .Bash_profile or modify .zshrc (if you use the words zsh), add the following statement
    export WORKON_HOME = $ HOME/.virtualenvs
    export PROJECT_HOME = $ HOME/workspace
    source /usr/local/bin/virtualenvwrapper.sh
  • mkvirtualenv ENV: create a running environment ENV
  • rmvirtualenv ENV: Delete operating environment ENV
  • mkproject mic: Creating runtime environment mic and mic project
  • mktmpenv: Create a temporary runtime environment
  • workon bsp: bsp work in the operating environment
  • lsvirtualenv: Lists the available operating environment
  • lssitepackages: Lists the current environment installed the package

Environment created is an independent, non-interfering, without the need to use sudo permissions pip to manage packages.

Documentation: https://virtualenvwrapper.readthedocs.org/en/latest/

Remote SSH

fabric: Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return.

from fabric.api import *
    
# server list
env.hosts = [ 'user@server1', 'user2@server2']

def ls_home():
    with cd('/home/username/'):
        run('ls')
    

Official website: https://www.fabfile.org/
Documentation: https://docs.fabfile.org/

Top comments (0)