Language - Python

From Phidgets Support
Revision as of 22:27, 5 June 2025 by Patrick (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Get Started

With the Phidget22 Python library, it's easy to create Python applications that work with Phidget devices.

Python Libraries

pip Package

The Phidget22 Python library is available as a pip package. Most development environments provide built-in tools to manage packages. View the Development Environment Configuration section below for examples.

macOS Considerations

Phidget devices running a HID USB stack require the installation of the macOS libraries or the standalone Phidget Control Panel (download here).

To determine what USB stack your Phidget device is on, navigate to the product page and then to the specification tab, and look for the USB Stack specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.

Javascript networkserver webusb spec.png

Linux Considerations

Linux restricts access to USB devices to the root user. To run your Python application as a regular user, you'll need to set up udev rules on your system.

Source Files

The Phidget22 Python library source files are available here.

Development Environment Configuration

Most development environments provide built-in tools to manage Python interpreters, packages, and virtual environments. See the examples below for more information.

Installing a Python Interpreter

If you don't already have a Python interpreter installed, you can download and install one from python.org or through package managers like Homebrew.

Visual Studio Code

Instructions
Install the Python extension for Visual Studio Code.
Language python vscode install.png
Next, create a directory and open it in Visual Studio Code. You can do this by opening Visual Studio Code and selecting File > Open Folder...
Language python vscode newfolder.png
Open the Command Palette (Ctrl + Shift + P), type Python: Create Environment, and press Enter. Select Venv when prompted.
Language python vscode newvenv.png
Next, select your preferred Python interpreter from the list. You may need to browse to find it.
Language python vscode selectinterpreter.png
Open a new terminal. You can do this through the Command Palette again (Ctrl + Shift + P), by typing Terminal: Create New Terminal. Install the Phidget22 pip package:
#Windows
py -m pip install phidget22 

#macOS
python3 -m pip install phidget22 

#Linux (Debian)
python3 -m pip install phidget22
Language python vscode installpackage.png
Finally, add your Python file and run it using the button in the top right corner.
Language python vscode runcode.png

PyCharm

Instructions
Create your PyCharm project and navigate to Settings:
Windows pycharm settings.jpg
Next, navigate to Project > Project Interpreter and click on the + symbol:
Windows pycharm addpackage.jpg
Search for phidget22 and install the package:
Windows pycharm installpackage.jpg
Finally, add your Python file and run it using the button at the top of the screen:
Windows pycharm run.png

Example Code

Navigate to our Code Sample Generator and select Python to view and download code samples that are tailored to your specific device.

Language python codesample.png

API

Phidget22 API