My system python3 version is 3.6. I need to install python3.9 in a directory, and run it.

First we need to add the deadsnakes repo for new python versions. Otherwise Ubuntu cannot get newer versions.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9 python3.9-venv python3.9-dev
sudo apt install python3-venv
python3.9 -m venv venv

Now, we have created a virtualenv folder named venv.

Activate it:

. venv/bin/activate

For django, you will need to install all the requirements again.