From 2bae6a0d3a86ccd9877f1716400c445c503c6956 Mon Sep 17 00:00:00 2001 From: "John M. Penn" Date: Tue, 1 Aug 2023 16:46:04 -0500 Subject: [PATCH] Add HOWTO for Python VIrtual Environment. --- docs/howto_guides/How-To-Guides.md | 3 +- .../How-To-Python-Virtual-Environment.md | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docs/howto_guides/How-To-Python-Virtual-Environment.md diff --git a/docs/howto_guides/How-To-Guides.md b/docs/howto_guides/How-To-Guides.md index db099956..104faf2d 100644 --- a/docs/howto_guides/How-To-Guides.md +++ b/docs/howto_guides/How-To-Guides.md @@ -8,4 +8,5 @@ 01. [How do I create a model library to save compilation time?](/trick/documentation/building_a_simulation/Trickified-Project-Libraries) 01. [How do I use inherited templates in the input file?](How-To-Use-Inherited-Templates) 01. [How to Dump a Core-file on MacOS](How-to-dump-core-file-on-MacOS) -01. [How to Containerize Trick with Docker](How-To-Containerize-Trick-with-Docker) \ No newline at end of file +01. [How to Containerize Trick with Docker](How-To-Containerize-Trick-with-Docker) +01. [How to Setup a Virtual Python Environment](How-To-Python-Virtual-Environment) diff --git a/docs/howto_guides/How-To-Python-Virtual-Environment.md b/docs/howto_guides/How-To-Python-Virtual-Environment.md new file mode 100644 index 00000000..258dc71c --- /dev/null +++ b/docs/howto_guides/How-To-Python-Virtual-Environment.md @@ -0,0 +1,58 @@ +## HOWTO Setup a Python Virtual Environment + + +### Creating a Virtual Environment + +The following command creates a virtual Python environment: + +```% python3 -m venv ``` + +This command runs the ```venv``` module, to create a virtual environment. The +directory specified by `````` is created to store +the resources of the environment. It contains scripts to activate, deactivate, +and otherwise configure the environment. It also provides a place to install Python +modules for that particular environment. One can create multiple virtual environments, +each with different resources. + +For example, the following will create a Python virtual environment called ```myVenv``` +in your home directory. + +```% python3 -m venv ~/myVenv``` + +### Activating the Virtual Environment + +To activate the virtual environment, execute the following: + +``` +% source myVenv/bin/activate +``` + +Note that the name of virtual environment is added to the command prompt. + +### Installing Python Modules Into Your Virtual Environment + +Use the following command to install Python modules into the virtual environment: + +``` +(myVenv) % python3 -m pip install +``` + +For example, the Trick test suite, which uses TrickOps which requires PyYAML. +This Python module would be installed as follows: + +``` +(myVenv) % python3 -m pip install PyYAML +``` + +Every time ```myVenv``` is activated, the PyYAML module will be available. + + +### Deactivating the venv Shell +To deactivate the venv shell, execute the following: + +```(myVenv) % deactivate``` + + +The above should get you going. If you need more details, the following tutorial is pretty good. +[RealPython Tutorial](https://realpython.com/python-virtual-environments-a-primer/). +