Python Install

First, Download source files and perform configurations. enable-optimizations is a commonly selected option for source installation.

./configure --prefix=/path-to-python/Python-xxx --enable-optimizations		# use Python-xxx for naming convention

Note: Use ./configure --help less to check detailed configurations.

Then, build Python source with make and install the binary after the building with make install:

$ make -j$(nproc)       # use all cpus for compile
$ sudo make install     # add sudo for admin install if python-path is set to /opt or /usr

Next, add the Python executable path in .bashrc and source it:

$ export PATH=$PATH:/path-to-python/Python-xxx
$ source .bashrc

Optional

Install the package virtualenv:

$ /path-to-python/Python-xxx/bin/pip3 install virtualenv 

Note: If Python is installed system-wide (in /opt or /usr), we need sudo to install the virtualenv package in the Python directory. Otherwise, the package will be installed in the current user’s .local directory.

Then, create a virtual environment and source the environment:

$ python3.x -m virtualenv env_name      # create env_name environment in the current directory
$ source env_name/bin/activate

Standard venv Module

Since Python 3.3, the venv module, which creates lightweight virtual environments, has been integrated into Python official distributions. The venv module contains partial features of the virtualenv module. Therefore, for simple virtual environment creation and usage, there is no need to install the virtualenv package.

$ python3.x -m venv myvenv    # create myvenv environment in the current directory using venv module

Check the post Python Virtual Environments for more details.