Python Setup

The lab computers have all required software pre-installed. If you want to use your own computer, follow the steps below.

Note for Mac users: This guide focuses on Windows because several hardware drivers are Windows-only:

  • NI-DAQmx (data acquisition with USB-6009) — Windows only
  • Thorlabs Kinesis (motor control) — Windows only
  • NI-VISA (instrument communication) — available for Mac

If you have a Mac, you can install Python and the core packages (NumPy, SciPy, Matplotlib, etc.) for data analysis on your own computer, but you’ll need to use the lab computers for data acquisition and motor control.


Install Python (Windows)

We recommend using the Python Install Manager, the official tool from python.org for managing Python on Windows.

Option A: Download from python.org (Recommended)

  1. Go to python.org/downloads
  2. Click “Download Python install manager”
  3. Run the installer and follow the prompts

Option B: Install from Microsoft Store

Search for “Python Install Manager” in the Microsoft Store and install it.

Troubleshooting: If py list --online gives an error about “legacy py.exe”, open Settings → Apps → Installed Apps, search for “Python Launcher”, and uninstall it.

After installation, open a terminal (PowerShell or Command Prompt) and install Python:

py install 3.12

You can verify the installation with:

py --version

To see all available Python versions:

py list --online

Install Python (Mac)

  1. Go to python.org/downloads/release/python-31210
  2. Scroll down to Files and download the macOS 64-bit universal2 installer
  3. Run the installer and follow the prompts

Verify the installation by opening Terminal and running:

python3 --version

Install Required Packages

Once Python is installed, install the packages needed for this course.

On Windows:

py -m pip install uv numpy pandas matplotlib scipy nidaqmx jupyterlab pyvisa pyserial pythonnet uncertainties

On Mac:

python3 -m pip install uv numpy pandas matplotlib scipy jupyterlab uncertainties

Note: Hardware interface packages (nidaqmx, pythonnet, pyvisa, pyserial) are omitted since Mac users will use the lab computers for hardware interfacing.

Or download our requirements.txt and run:

On Windows:

py -m pip install -r requirements.txt

On Mac: You’ll need to install packages individually (as shown above) since the requirements file includes Windows-only packages.


Install Hardware Drivers (Windows only)

Mac users: Skip this section. These drivers are Windows-only; use the lab computers for hardware interfacing.

NI-DAQmx (for data acquisition)

Required for the USB-6009 and other NI DAQ devices.

Download NI-DAQmx from National Instruments

After installation, verify by running in Python:

import nidaqmx
print(nidaqmx.system.System.local().driver_version)

NI-VISA (for instrument communication)

Required for communicating with bench instruments (oscilloscopes, function generators, power supplies, DMMs).

Download NI-VISA from National Instruments

After installation, verify by running in Python:

import pyvisa
rm = pyvisa.ResourceManager()
print(rm.list_resources())  # Lists all connected instruments

Thorlabs Kinesis (for motor control)

Required for Week 4 of the Gaussian Beams lab (automated beam profiling).

Download Thorlabs Kinesis

After installation, the Kinesis DLLs will be located at:

C:\Program Files\Thorlabs\Kinesis\

Verifying Your Setup

Windows: Run this test to verify everything is installed correctly:

# Test core packages
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from uncertainties import ufloat

print("Core packages: OK")

# Test DAQ (only works if hardware connected)
try:
    import nidaqmx
    system = nidaqmx.system.System.local()
    print(f"NI-DAQmx version: {system.driver_version}")
except Exception as e:
    print(f"NI-DAQmx: {e}")

# Test VISA
try:
    import pyvisa
    rm = pyvisa.ResourceManager()
    resources = rm.list_resources()
    print(f"VISA resources found: {len(resources)}")
except Exception as e:
    print(f"PyVISA: {e}")

print("\nSetup complete!")

Mac: Run this test to verify the core packages are installed:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from uncertainties import ufloat

print("Core packages: OK")
print("\nSetup complete!")

Back to Python Resources