Using Pipenv
note
In the past, we have recommended that everyone use pipenv
for RVR+/RVR Python projects. If you are only using your Raspberry Pi for projects with RVR+/RVR, or you're not worried about impacting your system Python installation, it is generally easier to skip pipenv
as shown in our advanced setup instructions.
Using a Python Virtual Environment
Pipenv is a tool used to manage Python virtual environments (also known as VMs). It's considered good practice to run python projects (like our SDK) in a VM in order to keep all dependencies local to a project folder (Pipenv is not the only such tool available - see PEP-405 for more information) . This is done in order to not interfere with the Raspberry Pi's global libraries and tools, including the default version of Python, which other projects might depend on. In the preconfigured Raspbian image, a virtual environment is already set up in the SDK root directory, /home/pi/sphero-sdk-raspberrypi-python
, and you can optionally use it.
To launch the virtual environment, enter the following command:
pipenv shell
Installing the RVR+/RVR SDK Dependencies
If you are not starting from the Sphero preconfigured SD card image, you'll need to set up a Python virtual environment yourself before you use it. Once you've cloned the SDK, you can use a helper script that we wrote to make VM setup easier.
caution
This hasn't been tested yet
To set up a Python virtual environment with all the dependencies needed by the RVR+/RVR SDK, just run the following commands:
# Change this as needed if you decided to put your copy of the SDK in a different location
cd ~/sphero-sdk-raspberrypi-python
# Run the pipenv setup script
./tools/pipenv-setup.sh
note
This will take a while, and may look like it has gotten stuck at times. On Pi Zero W, it may not work.
Starting Programs
Once your RVR+/RVR is connected to your Pi, any time you want to work on RVR+/RVR python programs, be sure to start the VM from within the root SDK folder.
Assuming the SDK is located at /home/pi/sphero-sdk-raspberrypi-python
, to ensure you are in the right place, use the following command:
cd ~/sphero-sdk-raspberrypi-python
The character ~
represents the /home/pi
directory.
Now activate the VM with the following command:
pipenv shell
If you see the name of the SDK folder in parentheses before your command prompt, you are now in a project-specific VM!
If you'll be running the example scripts from the getting_started folder, you can use cd
to get to the directory of the example you'd like to execute, and then you can run that code using:
python scriptname.py
Exiting the VM
Once you are finished working with the SDK, you can exit the VM in one of two ways.
- by issuing the following command:
exit
- by pressing
Ctrl + D
.
Turning Off Your Raspberry Pi
Once you are finished using your Raspberry Pi and RVR+/RVR, make sure to shut down your Raspberry Pi:
sudo shutdown now