Here you will find notes, tutorials, READMEs, procedures, how to's for C++ Python JavaScript SQL Docker NodeJS and other stuff.
My goals in developing software are to deliver quality reliable software that is maintainable and testable. I want to share all the little tasks I perform in setting up Python and C++ projects so that they can be built on Mac, Windows, Linux, AWS EC2, AWS Lambda, Linode, Digital Ocean, Andriod, IoS, Rasberry Pi and ESP32.
- How to create a Anaconda Python Environment
- What is the anaconda base environment.
- Setting the Python runtime in Visual Studio Code
- Setting the debug target of a C++ binary in Visual Studio Code
- How to pass arguments to a Debug target in VS Studio Code
- How to add Boost C++ Library to A CMake project
- Pytest Debugging in VS Code
There are many ways to create a Python virtual environments, the advantage of using Anaconda is that you will not have to install a C compiler and build packages yourself. Conda is stable and ahs few operational problems. (Note that install a C compiler on Windows using Visual Studio Code with also result in installing Python 2.7 and many other tools.) If you want to get up and running ASAP, then Anaconda Python is a good choice. There are other ways to manage packages and environments such as Poetry and PyEnv whic I will cover in other procedures.
-
Install Anaconda on Windows
- Follow this Installing on Windows
-
Create a fresh Anaconda virtual environment
conda create --name myenv python=3.9
1.a. Updating
You may be asked to update conda. I have had some issues updating conda to the latest version.
conda update -n base -c defaults conda
- To activate the environment
conda activate myenv
- To deactivate the environment
conda deactivate
- To install Python Packages into the environment
conda activate myenv
pip install -r requirements.txt
- To remove the environment
If for some reason you need to remove the environment and start over.
conda env remove --name myenv
- To list all the packages in a Python environment
conda list
If you type conda activate
you will be dropped into teh base anaconda environment. One way to find out about this environment is to type conda list
which will display all the packages that are installed by default. A freshly created Anaconda package will have a "base" installation of Python packages. The packages about to be downloaded and installed by the default package plan are listed when a new anaconda environment is about to be created.
## Package Plan ##
environment location: G:\ProgramData\Anaconda3\envs\myenv
added / updated specs:
- python=3.9
The following packages will be downloaded:
package | build
---------------------------|-----------------
certifi-2021.10.8 | py39haa95532_2 152 KB
openssl-1.1.1m | h2bbff1b_0 4.8 MB
sqlite-3.37.0 | h2bbff1b_0 785 KB
wheel-0.37.1 | pyhd3eb1b0_0 33 KB
------------------------------------------------------------
Total: 5.8 MB
The following NEW packages will be INSTALLED:
ca-certificates pkgs/main/win-64::ca-certificates-2021.10.26-haa95532_2
certifi pkgs/main/win-64::certifi-2021.10.8-py39haa95532_2
openssl pkgs/main/win-64::openssl-1.1.1m-h2bbff1b_0
pip pkgs/main/win-64::pip-21.2.4-py39haa95532_0
python pkgs/main/win-64::python-3.9.7-h6244533_1
setuptools pkgs/main/win-64::setuptools-58.0.4-py39haa95532_0
sqlite pkgs/main/win-64::sqlite-3.37.0-h2bbff1b_0
tzdata pkgs/main/noarch::tzdata-2021e-hda174b7_0
vc pkgs/main/win-64::vc-14.2-h21ff451_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
wheel pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
wincertstore pkgs/main/win-64::wincertstore-0.2-py39haa95532_2
Proceed ([y]/n)?
When looking at this list of package I see the "Hollywood A-List" of Python packages. First, let's just ponder for 1 second why Python is loved.
Could it be #1 sqlite 3?
Yes, that's right. It's Python the only language with its own built-in in-memory file-based SQL relational database. Instantaneously create as many relational databases as you need. Most applications only need one, by the way. The fact that Python applications can use a relational database without installing any additional software only adds to the many people love the Python programming language.
I think the main three packages are number one python, number two pip and number three setuptools. The fact that a Python environment contains Python itself is the entire point of a virtual Python environment. Only there is nothing "virtual" about it. It's so not virtual that it in fact has it's own copy of the Python executable. But the next two package say it all. Number two is pip.
-
Create a folder called .vscode
-
add a file called settings.json if it does not already exist
-
activate your Python environment
-
do a which python to get the full path of your Pyrhoin executable
-
Add the key value pair python.pythonPath to the settings.json file.
{
"python.pythonPath": "/home/tonyl/anaconda3/envs/dev39/bin/python",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
-
Create a folder called .vscode
-
add a file called launch.json if it does not already exist
-
For a project with a Cmake target_sources of "hello".
{
"name": "hello",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/hello_artefacts/Debug/hello.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
},
- The VS Code debugger will now add "hello" in its list of debug launch targets.
- In .vscode\launch.json add an args key value pair.
{
"name": "reverse 01",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/datagen/scripts/dg.py",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"args": [
"reverse",
"--server=postgresql",
"--hostname=localhost",
"--username=practice",
"--password=<<YOUR PASSWORD>>",
"--database=adventureworks",
"--port=5432",
"--filter_nulls=Y",
]
},
-
Download Boost for yoru system
-
In CMakeLists.txt, set Boost_INCLUDE_DIR to the location you downloaded and unzipped Boost
-
In CMakeLists.txt, add find_package and INCLUDE_DIRECTORIES for boost.
-
Example:
set(Boost_INCLUDE_DIR G:/music-dev/projects/boost_1_78_0)
find_package(Boost 1.78.0)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
- In a C++ file you may now include Boost include files.
#include <boost/format.hpp>
void Rectangle::report() {
std::cout << boost::format("%1% (%2% %3% %4% %5%) \n") % name % x % y % w % h;
}
-
add the following to .vscode\settings.json
{ "python.pythonPath": "<<<PATH TO YOUR PYTHON>>>", "python.testing.unittestEnabled": false, "python.testing.nosetestsEnabled": false, "python.testing.pytestEnabled": true, "python.testing.pytestArgs": [ "--pdb" ], "git.ignoreLimitWarning": false }
-
add this to your .vscode\launch.json
{ "name": "PyTest", "type": "python", "request": "launch", "stopOnEntry": false, "module": "pytest", "args": [ "-sv" ], "cwd": "${workspaceRoot}", "env": {}, "envFile": "${workspaceRoot}/.env", "debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput" ] },