venv - madBeavis/PimpMyAtv GitHub Wiki

What is and why use a virtual environment

A virtual environment allows you to have python dependencies on a per project basis. Your distro will have a specific python and dependency requirements, which you should not mess with. It could be a theme, but this is another case of just cause you can tinker with it doesn't mean you should.

You use a venv for each python project, such as MAD and PokeAlarm, so that each program has the proper dependencies it requires and does not muck up your system python and/or both other programs. Each project may even have different python version requirements. Shit gets messy quick, so just do virtual environments.

MAD python

Since MAD requires Python 3.7 or 3.8, you have to install one of them if your distro came with say 3.6 or 3.9 for MAD to work properly. Google YourDistroName install python 3.8 to find out how to do it for your distribution. For the purpose of this page, we will be using python 3.8 for subsequent examples.

Install venv

Make sure your distro is up to date with apt update and then apt upgrade.

Issue the command pip3 install --upgrade pip to upgrade pip3. Then install virtualenv with the following command pip3 install virtualenv. If you already have virtualenv installed, you can upgrade it with pip3 install --upgrade virtualenv.

Where to make venv

Make a decision where you want to install virtual environments. Some say in one folder for all projects, some say in the program that you make the virtual environment for, such as in the MAD folder. It is up to you, not my pig and not my farm. I am lazy, so I like easy references so I just do it in say MAD's directory for its venv. For the following examples, I will presume the MAD folder for MAD's venv and say PokeAlarm's folder for its venv.

There is no need to activate your venv if done like outlined here. Our purpose here is to get running and have separate venv for each program, adding them to your path via activation does not make sense in our usage circumstance. Every venv will be specifically referenced in subsequent commands.

Utilizing your venv

To use pip3 or python3 for your venv, you must reference it specifically. If you do just plain old python3, it will reference your system's python3 unless you have changed shit up. To use your venv python3, you have to do PathToVenv/bin/python3. Just copy and paste commands in the following sections, you should figure it out.

Make a venv for MAD

Change the the directory that you installed MAD. Issue the following command to make a venv for MAD, python3.8 -m venv venv. It will do some operations and make a venv for MAD. Then install the requirements for MAD with ./venv/bin/python3 pip3 install -r requirements.txt and let it do its thing. You can start MAD with ./venv/bin/python3 start.py to give MAD a test run. Running MAD in a console is for plebes, so run it with pm2.

Make a venv for other programs

Figure it out based off the prior commands, pitter patter. Adjust for directories and different python version requirements.

Further reading

The prior is a quick and simple to get you going with a venv, nothing more. Below are some reference materials, otherwise use up some of that always seemingly limited googlefoo.