TEK 5030 - Getting started on MacOS
These instructions have been tested on MacOS Monterey on a MacBook Air 2018.
In this guide we will:
-
Install Homebrew
Homebrew is "the missing package manager for MacOS", and if you haven't used it before, it's about time! It will simplify your life as a programmer quite significantly. Head over to https://brew.sh/ to read more.
-
Install VS Code editor
We will here document how to get started with TEK 5030 and VS Code editor. We choose VS Code because we can then maintain lab guides that will hopefully work on both Mac, Linux and Windows.
If you rather use Xcode, then I assume that you have a certain level of experience and won't need a guide ;-)
-
Install Conan (for C++)
Conan is a free and open source C++ package manager that we will use to maintain dependencies for our projects. Conan can be utilized on both Linux, Mac and Windows. Conan is created with Python, so we will install Python as well. In any way, it's convenient to have Python installed in case you want to solve the labs using Python. There is no downside to reading the "getting started" section of the conan documentation, so please take a look. If you intend to only program the labs using Python, you can skip the installation of conan.
(Conan will deprecate https://github.com/tek5030/setup_scripts, which is a set of helper scripts for system wide installation of C++ dependencies on Ubuntu 18.04).
-
Try to compile a simple C++ program using Visual Studo Code
-
Try to run the same program in Python
Install Homebrew
Open a terminal and install Homebrew as documented on their front page:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If you already have Hombrew installed, it's sensible to update before proceeding:
brew update
Install VS Code editor
Now that you have Homebrew, installing VS Code is a walk in the park:
brew install --cask visual-studio-code
For the curious: What is Homebrew Cask??
Make sure you have a C++ compiler (clang)
Clang may already be installed on your Mac. To verify that it is, open a macOS Terminal window and enter the following command:
clang --version
If Clang isn't installed, enter the following command to install the command line developer tools:
xcode-select --install
Using Clang in Visual Studio Code: https://code.visualstudio.com/docs/cpp/config-clang-mac
Install Python
We will install python3.8, since that is the version we have on the lab computers.
brew install python@3.8
Install VS Code extensions
To make it easier to automate and configure VS Code, it is possible to list, install, and uninstall extensions from the command line. We will utilize this feature in order to install a handfull of extensions that are usefult for C++ and Python development:
code --install-extension ms-vscode.cpptools
code --install-extension ms-vscode.cpptools-extension-pack
code --install-extension jeff-hykin.better-cpp-syntax
code --install-extension ms-python.python
Extensions can also be installed graphically from within VS Code. Read more here: https://code.visualstudio.com/docs/editor/extension-marketplace
Install conan
brew install conan
conan profile new default --detect # <-- Important step
Our first C++ program
Type the following in a new Terminal window:
git clone https://github.com/tek5030/lab_00_solution.git
cd lab_00_solution/cpp
conan install . --install-folder build
vscode .
It is outside the scope of this guide to explain the usage of conan in-depth, but in short:
- The command
conan install . --install-folder build
will install thedependencies
of our project.
The dependencies are listed in aconanfile.txt
within our project. It will be parsed by conan. - The installation path of each dependency (the actual libraries) is somewhere within the directory
~/.conan/data
. - Inside the
build
folder, conan will generate files that will help your build system locate the dependencies. - (Just so you know, you can never do anything wrong if you delete the contents of
~/.conan/data
. The worst thing that can happend is that you will experience a time consuming reinstallation of dependencies when building your next project.)
Now we will go through the procedure of building and running the example project:
Upon launch of VS Code, expect to see a dialog like this: Press Yes

In the next diaglog, appearing at the top of the program window, select your compiler. I chose "Unspecified (Let CMake guess (...)"

Now, at the bottom toolbar of VS Code, we will press a few buttons.

First press the "CMake: [Debug]: Ready". In the following dialog, I chose "Release"

Next, press the "cogwheel Build" to build your project.
Then, press the [all] - button and select lab_00_intro EXECUTABLE
, so that we can run our program.

Press the play button to run your program. The first time you launch, expect to see a dialog similar to this: Press OK.

(If you screw this up and click Deny, just follow the instructions of the error message if camera is denied access)
OpenCV: camera access has been denied. Either run 'tccutil reset Camera' command in same terminal to reset application authorization status, either modify 'System Preferences -> Security & Privacy -> Camera' settings for your application.
If everything goes as expected, expect to see live video feed from your camera (it might show up behind your vscode window) 🤩

Press q
to close the window.
Fallback solution
If all the dialog boxes and clicking in VS Code does not work out for you, this command line approach should work if everything is set up correctly:
cd ~/tek5030/lab_00_solution/cpp
conan install . --install-folder build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
./lab_00_intro
Python
While we're at it, let's try to get the python lab running as well.
Go to your terminal and into the directory lab_00_solution/py
. Continue with the following commands:
cd ~/tek5030/lab_00_solution/py
python3.8 -m venv venv
source venv/bin/activate.
# expect to see (venv) at the beginning of your prompt.
pip install --upgrade pip # <-- Important step!
pip install -r requirements.txt
python main.py
You might get this dialog again: Press OK

Now, expect success.
Python in VS Code
In my experience, it's best to set up the virtual environment before launching VS Code, but we'll try both. I assume you already typed all the previous commands, so now let's just
(venv) code . # assumed you are in the "py" directory, and venv is already activated
When you select main.py
in the file explorer to the left, you should hopefully see a toolbar like this on the bottom right of VS Code:

If your view is like mine, with "3.8.16 ('venv': venv)" in the lower right, all you have to do is to press the play in the upper right:

Expect success 💪
Let's assume you did not create a virtual environment, but went straigt into VS Code:
cd ~/tek5030/lab_00_solution/py
code .
For me, the toolbar looks like this, with a yellow "⚠️ Select Interpreter" on the lower right toolbar.

Here are the alternatives on my computer, but unfortunately, none of these will suffice, as we have not installed the dependencies in requirements.txt
yet.

It's a good habit to create virtual environments, to keep dependencies of each project local to that project. It is possible to do system wide installation of all dependendencies, but the common advice is not to. Just google "why use python virtual environments" if you need to be convinced, I have no intentions of replicating Internet here :)
Let's use the opportunity to learn how to open a terminal within VS Code:
- Press Command + Shift + P
- Type "Terminal"
- Select "Terminal: Create New Terminal (In Active Workspace)
- (I don't know why every word is capitalized, don't blame me)

In the new terminal that opened, type
python3.8 -m venv venv
in order to create the new virtual environment.
Whoa, clever VS Code detected the new environment!

Select "Yes". Still, we must continue with the installation of requirements:
pip install --upgrade pip
pip install -r requirements.txt
What happens if you don't?
Press the play button to find out:
import cv2
ModuleNotFoundError: No module named 'cv2'
- Ah, forgot to install the requirements!
pip install -r requirements.txt
(oups, did upgrade pip!)
WARNING: You are using pip version 22.0.4; however, version 22.3.1 is available. You should consider upgrading via the '(...)/python3.8 -m pip install --upgrade pip' command.
Okay, so on this computer, it seems we're actually fine and get away with just a warning. On the Jetsons on the lab (Ubuntu 18.04), however, the installation will fail, and we are required to upgrade pip before proceeding.
Anyhow, upgrading pip in the virtual environment won't hurt, so just keep it as a habit as well.
That's it(?)
Good luck with the rest of tek5030 🤓