Skip to content

00. Installation

Overview

The document that introduce how to install Python and setting Python at the first place.

Process

Choose one of following sections to follow.

  1. Download a Python release at Official Python Download

Download Snapshot

  1. Setting PATH, required admin previledges in your laptop/computer

  2. [Optional] If you using VSCode (Coding IDE), must read through VSC Python tutorial

  3. Then, setting Interpreter by using Ctrl+Shift+P then typing Python: Select Interpreter and choose the Path

Check the Python is on the requirement

import sys

# Extract
major, minor, micro, releaselevel, serial = sys.version_info

# Required
if not all([major >= 3, minor >= 9]):
    raise RuntimeError(f"Python version required to >= 3.9.x release")

Virtual environments

We strongly recommend using virtual environments when developing code in dbt-core. We recommend creating this virtualenv in the root of the dbt-core repository. To create a new virtualenv, run:

python3 -m venv env
source env/bin/activate

This will create and activate a new Python virtual environment.

Vitural Environments

Overview

Benefit:

  • Seperated environment to develop per project

  • Diffents dependencies

setup.sh
#!/bin/bash

# Configuration

# Vitural environment
declare VITURAL_ENV=venv

# Python Execution, $(which py)
declare PY_CMD=python

echo -e "\e[34m[1] Create requirement folders:\e[0m";
for fold in logs outputs temp $VITURAL_ENV
do
    if [ ! -d $fold ];
    then
        mkdir $fold;
        echo -e "\e[32mCreated $fold folder\e[0m";
    else
        echo -e "\e[32m$fold has been established\e[0m";
    fi;
done;

echo -e "\e[34mEstablished platform compatible\e[0m";
case "$OSTYPE" in
    msys*)
        echo "OS: Window >"
        declare PY_CMD=python
        declare ACTIVATE_DIR=Scripts
    ;;
    linux*)
        echo "OS: Linux >"
        declare PY_CMD=python3
        declare ACTIVATE_DIR=bin
    ;;
    *)
        echo "Not supported for this os: '$OSTYPE'"
    ;;
esac

# [Off] When build successful #!/bin/python3
# echo -e "\e[34mSet up vitural environment at \e[30m'$VITURAL_ENV'\e[0m\e[0m";
# $PY_CMD -m venv $VITURAL_ENV;

# echo -e "\e[34mActivate environment\e[0m";
# source $VITURAL_ENV/$ACTIVATE_DIR/activate;

echo -e "\e[34mUpgrade PIP version ...\e[0m";
$PY_CMD -m pip install --upgrade pip;

echo -e "\e[34mInstall requirements packages:\e[0m";
cat requirements.txt;
$PY_CMD -m pip install -r requirements.txt;

for pkg in httr sys_metadata utils_mysql
do
    cd $(pwd)/src/$pkg;
    $PY_CMD -m pip install . --force-reinstall;
    cd ../../
done;
#!/bin/bash

declare VENV=venv;

case "$OSTYPE" in
    msys*)
        declare ACTIVATE_DIR=Scripts
    ;;
    linux*)
        declare ACTIVATE_DIR=bin
    ;;
    *)
        echo "Not supported for this operating system type: '$OSTYPE'"
    ;;
esac;

source $VENV/$ACTIVATE_DIR/activate;

Reference

Troubleshooting

Before make any issue, make sure

  1. Read once again your code, since start to make sure you understanding the error

  2. Try to debug first, before you accquire one from other

  3. Read back the process, are you satify with the process

CMD opens Windows Store when I type 'python'

Action: Use the Windows search bar to find "Manage app execution aliases". There should be two aliases for Python. Unselect them, and this will allow the usual Python aliases "python" and "python3". See the image below.

Ref:

Setting PATH for Python

Using this keyword How to set the path and environment variables in Windows to search and there are a lot of suggestion tutorial to follow

Use one of download method

If you using Python Launcher for Windows, it settings differents Python path on your machine.

Even you setting the PATH, the Python still not change to the want Python version

Check if

which py
# yield C/windows/py

This is time you make sure to use one method only.

If you want to select the options, removed the Launcher in Control Panel > Programs > Uninstall ... progress.

There is required to refresh your machine after this to refresh session