diff options
author | Prabhu Ramachandran | 2021-08-22 17:36:38 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2021-08-22 17:36:38 +0530 |
commit | 0e76356043e3ed28a74ecb5c8f64094bc18f2115 (patch) | |
tree | fcab3f0f70bee0325cd2d09074b9f5986db35f6f /slides/devtools/venv.md | |
parent | 069bff2ed098913182be4c9317ef7c5a393d0716 (diff) | |
download | sees-0e76356043e3ed28a74ecb5c8f64094bc18f2115.tar.gz sees-0e76356043e3ed28a74ecb5c8f64094bc18f2115.tar.bz2 sees-0e76356043e3ed28a74ecb5c8f64094bc18f2115.zip |
Diffstat (limited to 'slides/devtools/venv.md')
-rw-r--r-- | slides/devtools/venv.md | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/slides/devtools/venv.md b/slides/devtools/venv.md new file mode 100644 index 0000000..3c57f2c --- /dev/null +++ b/slides/devtools/venv.md @@ -0,0 +1,247 @@ +--- +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 +--- + +<!-- #region slideshow={"slide_type": "slide"} --> +venv and pip: an introduction +====================== + +<br/> +<br/> +<br/> +<br/> + +<center> +August 22, 2021 +</center> + +<center> +Department of Aerospace Engineering, IIT Bombay +</center> + +<center> +Prabhu Ramachandran +</center> + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +Agenda +------ + +- Introduction to venv and pip +- Basic usage and practices +- Using with conda + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +Why +------ + +- The default option for Python +- Similar to conda but predates it + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +Installation +------------- + +- Part of your default Python install! +- Built-in usually + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +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 + + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +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 +``` + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +Other options +--------- + +- Inherit parent packages + +```bash +$ python -m venv myenv --system-site-packages +``` + +- Can also upgrade using `--upgrade` + +<!-- #endregion --> + + +<!-- #region slideshow={"slide_type": "slide"} --> +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 +``` + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +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 + + +<!-- #endregion --> + + +<!-- #region slideshow={"slide_type": "slide"} --> +More commands +------------------ + +```bash +$ python -m pip help +``` + +```bash +$ python -m pip list +``` + +```bash +$ python -m pip show numpy +``` + +<!-- #endregion --> + +<!-- #region slideshow={"slide_type": "slide"} --> +Requirements +-------------- + +- Create a requirements +```bash +$ python -m pip freeze +``` + +- Use this to install + +```bash +$ python -m pip install -r requirements.txt +``` + +<!-- #endregion --> + + +<!-- #region slideshow={"slide_type": "slide"} --> +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` + +<!-- #endregion --> + + +<!-- #region slideshow={"slide_type": "slide"} --> +More information +------------------ + +- https://packaging.python.org/guides/ +- https://realpython.com/python-wheels/ + +<!-- #endregion --> |