Python Interpreter Setting¶
Overview¶
Setting Python at the first place is always hard, especially if you first meet Python.
This document make sure the way you interact with Python on Windows (this is most cases) for Python developers to start develop.
Progress¶
Choose one of following sections to follow.
- Download a Python release at Official Python Download
-
Setting PATH, required
admin previledges
in your laptop/computer -
[Optional] If you using VSCode (Coding IDE), must read through VSC Python tutorial
-
Then, setting Interpreter by using
Ctrl+Shift+P
then typingPython: 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:
This will create and activate a new Python virtual environment.
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
Some useful
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
Detail Concept¶
Shebang Concept¶
If the first line of a script file starts with #!, it is known as a “shebang” line. Linux and other Unix like operating systems have native support for such lines and they are commonly used on such systems to indicate how a script should be executed. This launcher allows the same facilities to be used with Python scripts on Windows and the examples above demonstrate their use.
To allow shebang lines in Python scripts to be portable between Unix and Windows, this launcher supports a number of ‘virtual’ commands to specify which interpreter to use. The supported virtual commands are:
For example, if the first line of your script starts with
The default Python will be located and used. As many Python scripts written to work on Unix will already have this line, you should find these scripts can be used by the launcher without modification. If you are writing a new script on Windows which you hope will be useful on Unix, you should use one of the shebang lines starting with /usr.
Any of the above virtual commands can be suffixed with an explicit version (either just the major version, or the major and minor version). Furthermore the 32-bit version can be requested by adding “-32” after the minor version. I.e. /usr/bin/python2.7-32 will request usage of the 32-bit python 2.7.
New in version 3.7: Beginning with python launcher 3.7 it is possible to request 64-bit version by the “-64” suffix. Furthermore it is possible to specify a major and architecture without minor (i.e. /usr/bin/python3-64).
The /usr/bin/env form of shebang line has one further special property. Before looking for installed Python interpreters, this form will search the executable PATH for a Python executable. This corresponds to the behaviour of the Unix env program, which performs a PATH search.
Config Pytest¶
File Ini set up for
[pytest]
minversion = 6.0
addopts = -ra -q
testpaths = tests
console_output_style = progress
; Timeout in second
faulthandler_timeout= 60
; Enable log display during test run
log_cli = True
log_cli_level = INFO
log_cli_date_format = %Y-%m-%d %H:%M:%S
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_file = logs/pytest-logs.txt
; One or more Glob-style file patterns determining which python files are considered as test modules.
; Search for multiple glob patterns by adding a space between patterns:
python_files = test_*.py check_*.py example_*.py