Score:0

Avoid switching between two versions of python for each service in the same environment

in flag

I managed to install python 3.6 alongside python 3.10, the problem is that when 3.6 is selected in update alternatives, walinuxagent service works fine when while netbox, netbox-rq and nginx services doesn't; the opposite happening when 3.10 is selected.

A workaround is selecting each python version depending on which service I want to start. Is there a way to avoiding doing this every time?

Score:1
ec flag

The best way is not to change the default Python of the system, as some parts of the system and programs may rely on this specific version and may not work correctly with other / newer Python releases.

Installing another Python release in parallel is not a problem, but this Python release should be always referenced with the explicit release number.

For Ubuntu 18.04, Python 3.6 is the system's default and is run when python3 is called. A parallel installed Python 3.10 should be called with python3.10.

Score:0
in flag

One solution to avoid switching between Python versions every time is to create virtual environments for each service and specify the desired Python version in each virtual environment. A virtual environment is a self-contained Python environment that allows you to install packages and run scripts in isolation from other Python installations.

To create virtual environments, you can use the virtualenv package. Here is how you can create a virtual environment for each service:

Install virtualenv using the following command:

pip install virtualenv

Create a virtual environment for each service, specifying the desired Python version:

virtualenv -p /usr/bin/python3.6 walinuxagent-env
virtualenv -p /usr/bin/python3.10 netbox-env
virtualenv -p /usr/bin/python3.10 netbox-rq-env
virtualenv -p /usr/bin/python3.10 nginx-env

Activate each virtual environment before starting the corresponding service:

source walinuxagent-env/bin/activate
source netbox-env/bin/activate
source netbox-rq-env/bin/activate
source nginx-env/bin/activate

Now, each service will run with the desired Python version specified in the corresponding virtual environment, without the need to switch between Python versions every time. To deactivate the virtual environment and return to the global Python environment, you can use the deactivate command.

Note: You will need to install any required packages in each virtual environment using the pip install command.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.