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.
- Download a Python release at Official Python Download
-
Setting PATH, required
admin previledgesin your laptop/computer -
[Optional] If you using VSCode (Coding IDE), must read through VSC Python tutorial
-
Then, setting Interpreter by using
Ctrl+Shift+Pthen typingPython: Select Interpreterand 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:
This will create and activate a new Python virtual environment.
Vitural Environments¶
Overview¶
Benefit:
-
Seperated environment to develop per project
-
Diffents dependencies
#!/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
-
Read once again your code, since start to make sure you understanding the error
-
Try to debug first, before you accquire one from other
-
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.
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
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
Note
Read through: https://docs.python.org/3/using/windows.html
