Template:PT3 PYTHON LNX TRM: Difference between revisions
From Phidgets Support
No edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
<p>First, install <span>[https://www.python.org/downloads/ Python3]</span> if you haven't already.</p> | <p>First, install <span>[https://www.python.org/downloads/ Python3]</span> if you haven't already.</p> | ||
<p>Python 3. | <p> | ||
As of Python 3.11, you must use a virtual environment when installing externally managed packages. First, you need to install the virtual environment for your | |||
python version: | |||
</p> | |||
<div class="phd-command-line"><code>apt-get install python3.12-venv</code></div> | |||
<p>Next, create your virtual environment folder. We will name ours <b>PhidgetsExample</b>, but you can choose any name:</p> | |||
<div class="phd-command-line"><code>python3 -m venv PhidgetsExample</code></div> | |||
<p>This creates a folder for your new project. To activate the virtual environment, use the following command:</p> | |||
<div class="phd-command-line"><code>source PhidgetsExample/bin/activate</code></div> | |||
<p>Now that you're in the virtual environment, install the Phidget22 Python package with PIP:</p> | |||
<div class="phd-command-line"><code>pip3 install Phidget22</code></div> | <div class="phd-command-line"><code>pip3 install Phidget22</code></div> | ||
Line 73: | Line 88: | ||
<h2>Using the Code Samples</h2> | <h2>Using the Code Samples</h2> | ||
<p> | <p>Move the downloaded example into your virtual environment folder. If the virtual environment is still active, you can run the example:</p> | ||
<div class="phd-command-line"><code>python3 Python_Example.py</code></div> | <div class="phd-command-line"><code>python3 Python_Example.py</code></div> | ||
<p>Success! Your program is now running with Phidgets!</p> | <p>Success! Your program is now running with Phidgets! If you want to exit the virtual environment, type <b>deactivate</b>.</p> | ||
</div> | </div> | ||