Interact with Python virtual environment

Using python for mahcine learning projects is totally different from utilizing the language for productivity on daily tasks.

Python official website provides the documentations for venv1. This post2 contains a comprehensive guide on how to use the virtual environment.

There are lots of tutorials on how to setup, manage and dispose a python virtual environment using command lines. I decide to present this process directly from Jupyter notebook. Althrough running Jupyter lab is a bit difficult to do, I recommend you to install Visual Studio Code, it is really easy to run notebooks, suppose you have at least a version of Python3 installed on your PC or server. In addition, the code shown in the post and the jupyter notebook could be executed within a Python interactive session, this interactive session could be invoked by the command python in Windows or python3 in other platforms like Mac and Unix.

Desktop  python3 -m venv -h

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

options:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this environment.
  --upgrade-deps        Upgrade core dependencies (pip) to the latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.
Bash
The Venv environment is found and displayed in the Visual Studio Interpreter Selection Window
  1. venv — Creation of virtual environments[]
  2. Python Virtual Environments: A Primer[]

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *