linux_wiki:python

Python

General Information

Administration of Python environments.

Checklist

  • Distro(s): Enterprise Linux 6/7

OS System Package EPEL Software Collections
CentOS 6.x 2.6.6 3.4 2.7, 3.3, 3.4
CentOS 7.x 2.7 3.4, 3.6 2.7, 3.3, 3.4, 3.5
  • To avoid breaking system packages(ie yum uses python), let system packaged python versions stay maintained by the official repos.
  • Use EPEL/software collections along with something such as virtualenv to maintain development environments.

Python3 Install: EPEL

To install python 3.4 from the EPEL

  • 3.4
    yum install python34
  • 3.6
    yum install python36

Python3 Install: Software Collections

Software Collections allow for environments such as newer Python versions to be installed via repos and not conflict with the default system version.

See Software Collections Instructions


Pip

Pip is a Python package management tool to install modules.

Install Pip into a Python environment

  • Python2
    wget https://bootstrap.pypa.io/get-pip.py
    python get-pip.py
  • Python3
    wget https://bootstrap.pypa.io/get-pip.py
    python3.6 get-pip.py


Install devel packages that many pip builds rely upon

  • Python2
    yum install gcc python-devel
  • Python3.4
    yum install gcc python34-devel
  • Python3.6
    yum install gcc python36-devel

Python 2 vs Python 3 pip commands

  • Python 2
    pip <command>
  • Python 3
    pip3 <command>


List installed python modules

pip list


Show details about a Python module

pip show virtualenv


Search for a Python module

pip search "query"


Install a Python module

pip install virtualenv


Upgrade a Python module

pip install --upgrade scipy


Upgrade pip

pip install --upgrade pip


Uninstall

pip uninstall virtualenv

There is a global config file and per user config file locations.


Global pip config file - example to format columns for all users

/etc/pip.conf
[list]
format=columns


User pip config file - for additional config or to over ride the global

  • Create the pip config directory
    mkdir ~/.config/pip/
  • Create the pip.conf file and populate it
    vim ~/.config/pip/pip.conf
     
    #your config here

Python Modules

Some commonly installed Python modules.

Virtualenv “is a tool to create isolated Python environments.”

Site: https://virtualenv.pypa.io/en/stable/

  • Python2
    pip install virtualenv
  • Python3
    pip3 install virtualenv

PipEnv “automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever–important Pipfile.lock, which is used to produce deterministic builds.”

Site: https://github.com/pypa/pipenv

  • Python2
    pip install pipenv
  • Python3
    pip3 install pipenv

AWS CLI “is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.”

Site: https://aws.amazon.com/cli/

Pre-Reqs

yum install expat-devel

Install

  • Python2
    pip install awscli
  • Python3
    pip3 install awscli

Verify

  • Python2 and Python3
    aws --version

If you are seeing errors while using the aws cli about “SSL: CERTIFICATE_VERIFY_FAILED”

  • Point the aws cli to the system ca bundle (per user)
    vim ~/.bashrc
     
    # AWS CA Bundle
    export AWS_CA_BUNDLE="/etc/pki/tls/certs/ca-bundle.crt"
  • Source the file
    source ~/.bashrc

  • linux_wiki/python.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)