Python Virtual Environments
Maintaining different versions of Python can be a chore. Thankfully, there are many tools for managing Python environments; here are a few recommendations:
PyCharm IDE – great for developing code in Python, and can automatically create virtual environments for a codebase by detecting versions and dependencies from the
setup.py
orsetup.cfg
.Conda package manager – a Python package manager focused on scientific computing that can also manage virtual environments.
pyenv CLI – a shell based tool for installing and switching between different versions of Python and dependencies. I will give a brief tutorial of using
pyenv
below, but recognize that the instructions may change over time so thepyenv
documentation is the best place to look.
To create a Python 3.9 virtual environment, try the following steps:
Install pyenv:
if on Mac, use brew: brew install pyenv
if on a linux system, try pyenv-installer
if on Windows, try pyenv-win
Install Python 3.9:
in a shell, run
pyenv install 3.9.1
Activate Python 3.9 in the current shell
in the shell, run
pyenv shell 3.9.1
Proceed with the install of mosartwmpy:
in the same shell, run
pip install mosartwmpy
Now you can interact with
mosartwmpy
in this current shell sessionif you start a new shell session you will need to run
pyenv shell 3.9.1
again before proceedingthis new shell session should maintain all previously pip installed modules for Python 3.9.1