Skip to content

Latest commit

 

History

History
116 lines (75 loc) · 2.9 KB

python.md

File metadata and controls

116 lines (75 loc) · 2.9 KB

Python

Python is a popular and easy to use general purpose programming language that is heavily used in Data Analytics and Data Science as well as systems administration.

It's not as amazing for one-liners as Perl is though, which can boost shell scripts more easily.

Core Reading

Learning Python

DevOps Python tools

HariSekhon/DevOps-Python-tools

Shell scripts with Python

Shell scripts using Python and making it easier to install Python pip libraries from PyPI.

HariSekhon/DevOps-Bash-tools

Nagios Plugins in Python

HariSekhon/Nagios-Plugins

Python Library with Unit Tests

HariSekhon/pylib

VirtualEnv

Creates a virtual environment in the local given sub-directory in which to install PyPI modules to avoid clashes with system python libraries.

virtualenv "$directory_name_to_create"

I like top always the directory name venv for the virtualenv:

virtualenv venv

Then to use it before you starting pip installing:

source venv/bin/activate

This prepends to $PATH to use the bin/python and lib/python-3.12/site-packages under the local venv directory:

Now install PyPI modules as usual.

The venv/pyvenv.cfg file will contain some metadata like this:

home = /opt/homebrew/Cellar/python@3.12/3.12.3/bin
implementation = CPython
version_info = 3.12.3.final.0
virtualenv = 20.25.3
include-system-site-packages = false
base-prefix = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12
base-exec-prefix = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12
base-executable = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin/python3.12

Pipenv

https://pipenv.pypa.io/en/latest/

https://github.com/pypa/pipenv

Combines Pip and VirtualEnv into one command.

brew install pipenv

Creates a Pipfile and Pipfile.lock, plus a virtualenv in a standard location $HOME/.local/share/virtualenvs/ if not already inside one.

pipenv install

Activates the virtualenv

pipenv shell

Automatically converts a requirements.txt file into a Pipfile:

pipenv check

Dependency graph:

pipenv graph

Partial port from private Knowledge Base page 2008+