TEK5030

TEK5030 resource pages

<-- Home

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

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:

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

image

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

image

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

image

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

image

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.

image

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

image

(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) 🤩

image

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

image

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:

image

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:

image

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.

image

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.

image

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:

image

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!

image

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 🤓