--- jupyter: jupytext: text_representation: extension: .md format_name: markdown format_version: '1.2' jupytext_version: 1.3.2 kernelspec: display_name: Python 3 language: python name: python3 --- venv and pip: an introduction ======================



August 22, 2021
Department of Aerospace Engineering, IIT Bombay
Prabhu Ramachandran
Agenda ------ - Introduction to venv and pip - Basic usage and practices - Using with conda Why ------ - The default option for Python - Similar to conda but predates it Installation ------------- - Part of your default Python install! - Built-in usually Getting started --------- - Create an environments ```bash $ python -m venv --help ``` ```bash $ python -m venv myenv ``` - Creates a directory `myenv` - Is not self-contained but is isolated Activation/Deactivation ------------------------- - On Linux/MacOS ```bash $ source myenv/bin/activate ``` - On Windows ```bash > .\myenv\Scripts\activate ``` ```bash $ python >>> import sys >>> sys.prefix ``` ```bash $ deactivate $ rm -rf myenv ``` Other options --------- - Inherit parent packages ```bash $ python -m venv myenv --system-site-packages ``` - Can also upgrade using `--upgrade` Installation of packages ------------------ ```bash $ python -m pip install numpy ipython ``` - Specific versions ```bash $ python -m pip install vtk==9.0.1 ``` - Remove ```bash $ python -m pip uninstall vtk ``` More on installation ------------------ - Install from source directory ```bash $ python -m pip install . ``` - Editable installation ```bash $ python -m pip install --editable . ``` - Or `-e` - `--no-cache-dir`: Do not use the cached wheels - `--force-reinstall`: what it says - `--no-binary`: use if binary wheel is busted - The last will force a source build More commands ------------------ ```bash $ python -m pip help ``` ```bash $ python -m pip list ``` ```bash $ python -m pip show numpy ``` Requirements -------------- - Create a requirements ```bash $ python -m pip freeze ``` - Use this to install ```bash $ python -m pip install -r requirements.txt ``` Conda + requirements? ----------------- ```bash $ cat environment.yml name: myenv ... dependencies: - python=3.8 - ipython - pip - pip: - vtk - mayavi ``` - Use this directly with conda ```bash $ conda env create ``` - `--file fname.yml` if not `environment.yml` More information ------------------ - https://packaging.python.org/guides/ - https://realpython.com/python-wheels/