GoPiGo3 - using virtualenvs for OpenCV

I am trying to use OpenCV (which I have successfully installed) with RemoteCameraRobot using virtualenv. Here is what I tried:

pi@dex: source ~/.profile
pi@dex: workon cv
(cv) pi@dex: cd /gopigo3/Projects/RemoteCameraRobot
(cv) pi@dex: python remote_robot.py
Loading library without distance sensor
FATAL ERROR:
To update the firmware on Raspbian for Robots you need to run DI Software Update and choose Update Robot
CRITICAL:root:GoPiGo3 firmware needs to be updated

So I am unable to use the GoPiGo3 in a virtualenv. Is there a way to enable the GoPiGo3 to work in a virtualenv? I did find the post, “Is it possible to run the line follower module in a python 2 virtual environment?” I followed the steps given, but this did not completely solve the problem and I still get the fatal error.

Rick Torzynski

1 Like

To install the GoPiGo3 within a virtual environment, you first have to activate the environment and then run the following command:

curl -kL dexterindustries.com/update_gopigo3 | bash -s -- --user-local --bypass-gui-installation

You also seem to have to update the firmware of the GoPiGo3:

bash GoPiGo3/Firmware/gopigo3_flash_firmware.sh

Can you please try this out?

Thank you!

Robert,
Thanks for the reply. This fails:
(cv) pi@dex:~ $ curl -kL dexterindustries.com/update_gopigo3 | bash -s --user-local --bypass-gui-installation
bash: --: invalid option
Usage: bash [GNU long option] [option] …
bash [GNU long option] [option] script-file …
GNU long options:
–debug
–debugger
–dump-po-strings
–dump-strings
–help
–init-file
–login
–noediting
–noprofile
–norc
–posix
–rcfile
–restricted
–verbose
–version
Shell options:
-ilrsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 1198 0 --:–:-- --:–:-- --:–:-- 1194
100 178 100 178 0 0 252 0 --:–:-- --:–:-- --:–:-- 252
0 0 0 0 0 0 0 0 --:–:-- 0:00:01 --:–:-- 0
40 11707 40 4681 0 0 2619 0 0:00:04 0:00:01 0:00:03 2619
curl: (23) Failed writing body (2174 != 2759)

Where should I be when I run this?

Other script output:
(cv) pi@dex:~/Dexter $ bash GoPiGo3/Firmware/gopigo3_flash_firmware.sh
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘auto_detect_rpi’
Unsupported RPi version ‘’. Please report to support@dexterindustries.com

Hi @rick.torzynski,

That’s totally on me. There’s a missing -- in the command I’ve posted. I’ve edited my post, so can you check it again?

Thank you!

I did catch that and added the – to the command. Still no joy.

When working with OpenCV, using a virtual environment is pretty much standard practice - Adrian Rosebrock of Pyimagesearch uses virtualenvs when installing OpenCV. https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/

What about installing GoPiGo3 within a virtual environment? Might add some complexity to your install instructions, but should be doable.

What do you mean? It still doesn’t work? Can you expand on this?

That should work with the command I listed in one of the above posts. If you think of just installing the python package, then there’s no easy pip install ... option. We are actually thinking of adding this to our robots so that each one can be installed from PyPI, although I think we’d also need a sort of a CLI so that you can burn the associated firmware to the robot (GoPiGo3, GrovePi, BrickPi and so on).

Robert,

Sorry to not include more info - I was at work. Here is the output generated when I ran the update:
(cv) pi@dex:~/Dexter/GoPiGo3 $ curl -kL dexterindustries.com/update_gopigo3 | bash -s – --user-local --bypass-gui-installation
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 1201 0 --:–:-- --:–:-- --:–:-- 1210
100 178 100 178 0 0 364 0 --:–:-- --:–:-- --:–:-- 364
0 0 0 0 0 0 0 0 --:–:-- 0:00:01 --:–:-- 0
100 11707 100 11707 0 0 7966 0 0:00:01 0:00:01 --:–:-- 7966


| __ \ | |
| | | | _____ | | ___ _ __
| | | |/ _ \ / / / _ \ '|
| || | /> <| || / |
|
/ _
/_/_\_|| _
|
| | | | | ()
| | _ __ | | _ | | _ __ _ ___ ___
| | | ’
\ / \ | | | / __| | '| |/ _ / __|
| || | | | (
| | |
| _
\ || | | | /_ \
|
___|
| ||_,|_,|/_|| ||_||/


/ | ___ | _ ()/ | | /
| | _ / _ | |
) | | | _ / _ \ |
\
| |
| | (
) | __/| | |
| | () |) |
_
|_/|| ||_|__/____/

Welcome to GoPiGo3 Installer.
Updating GoPiGo3 for master branch with the following options:
–no-dependencies=false
–no-update-aptget=false
–bypass-rfrtools=false
–bypass-python-rfrtools=false
–bypass-gui-installation=true
–user-local=true
–env-local=false
–system-wide=false
Using “master” branch
Options used for RFR_Tools script: “–user-local master --use-python3-exe-too --update-aptget --install-deb-deps --install-python-package”
Installing RFR_Tools. This might take a while…
Updating RFR_Tools for master branch with the following options:
–install-python-package=true
–system-wide=false
–user-local=true
–env-local=false
–use-python3-exe-too=true
–update-aptget=true
–install-deb-deps=true
–install-gui=false
Updating debian repository within RFR_Tools
OK
Added NodeJS repo to source for apt-get for “stretch” distribution
Get:1 http://deb.nodesource.com/node_9.x stretch InRelease [4,623 B]
Get:2 http://archive.raspberrypi.org/debian stretch InRelease [25.4 kB]
Get:3 http://raspbian.raspberrypi.org/raspbian stretch InRelease [15.0 kB]
Fetched 44.9 kB in 1s (29.4 kB/s)
Reading package lists… Done
Installing debian dependencies within RFR_Tools. This might take a while…
Reading package lists… Done
Building dependency tree
Reading state information… Done
build-essential is already the newest version (12.3).
git is already the newest version (1:2.11.0-3+deb9u4).
i2c-tools is already the newest version (3.1.2-3).
libffi-dev is already the newest version (3.2.1-6).
libi2c-dev is already the newest version (3.1.2-3).
python-dev is already the newest version (2.7.13-2).
python-setuptools is already the newest version (33.1.1-1).
python3-dev is already the newest version (3.5.3-1).
python3-setuptools is already the newest version (33.1.1-1).
python-pip is already the newest version (9.0.1-2+rpt2).
python3-pip is already the newest version (9.0.1-2+rpt2).
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
Installing script_tools. This might take a while…
Done installing script_tools
Removing “auto_detect_rpi” to make space for the new one
Removing /usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg egg
Removing /usr/local/lib/python3.5/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.5.egg egg
Installing python package for RFR_Tools
running install
Checking .pth file support in /home/pi/.local/lib/python3.5/site-packages/
/home/pi/.virtualenvs/cv/bin/python -E -c pass
TEST FAILED: /home/pi/.local/lib/python3.5/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read “.pth” files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/home/pi/.local/lib/python3.5/site-packages/

and your PYTHONPATH environment variable currently contains:

''

Here are some of your options for correcting the problem:

  • You can choose a different installation directory, i.e., one that is
    on PYTHONPATH or supports .pth files

  • You can add the installation directory to the PYTHONPATH environment
    variable. (It must then also be on PYTHONPATH whenever you run
    Python and want to use the package(s) you are installing.)

  • You can set up the installation directory to support “.pth” files by
    using one of the approaches described here:

    https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.
Done installing RFR_Tools
Installing Dependencies for the GoPiGo3
Reading package lists… Done
Building dependency tree
Reading state information… Done
python-curtsies is already the newest version (0.2.11-1).
python-numpy is already the newest version (1:1.12.1-3).
python3-curtsies is already the newest version (0.2.11-1).
python3-numpy is already the newest version (1:1.12.1-3).
python-pip is already the newest version (9.0.1-2+rpt2).
python3-pip is already the newest version (9.0.1-2+rpt2).
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
Dependencies installed for the GoPiGo3
wiringPi VERSION is 236
FOUND WiringPi Version 2.36 No installation needed.
Removing blacklist from /etc/modprobe.d/raspi-blacklist.conf
SPI already removed from blacklist
Adding SPI-dev in /etc/modules
spi-dev already there
Making SPI changes in /boot/config.txt
SPI already enabled
Removing “gopigo3” to make space for the new one
Removing /home/pi/.virtualenvs/cv/lib/python3.5/site-packages egg
rm: cannot remove ‘/home/pi/.virtualenvs/cv/lib/python3.5/site-packages’: Is a directory
Removing /usr/local/lib/python2.7/dist-packages/gopigo3-1.2.0-py2.7.egg egg
Removing /home/pi/.virtualenvs/cv/lib/python3.5/site-packages egg
rm: cannot remove ‘/home/pi/.virtualenvs/cv/lib/python3.5/site-packages’: Is a directory
Removing /usr/local/lib/python3.5/dist-packages/gopigo3-1.2.0-py3.5.egg egg
running install
Checking .pth file support in /home/pi/.local/lib/python3.5/site-packages/
/home/pi/.virtualenvs/cv/bin/python -E -c pass
TEST FAILED: /home/pi/.local/lib/python3.5/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read “.pth” files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/home/pi/.local/lib/python3.5/site-packages/

and your PYTHONPATH environment variable currently contains:

''

Here are some of your options for correcting the problem:

  • You can choose a different installation directory, i.e., one that is
    on PYTHONPATH or supports .pth files

  • You can add the installation directory to the PYTHONPATH environment
    variable. (It must then also be on PYTHONPATH whenever you run
    Python and want to use the package(s) you are installing.)

  • You can set up the installation directory to support “.pth” files by
    using one of the approaches described here:

    https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.
cp: cannot create regular file ‘/home/pi/Desktop/gopigo3_control_panel.desktop’: Permission denied
Installing OpenOCD for GoPiGo3
Archive: openocd_compiled.zip
creating: openocd_compiled/
creating: openocd_compiled/files/
creating: openocd_compiled/files/openocd/
creating: openocd_compiled/files/openocd/scripts/
creating: openocd_compiled/files/openocd/scripts/interface/
creating: openocd_compiled/files/openocd/scripts/target/
inflating: openocd_compiled/files/openocd/scripts/target/at91samdXX.cfg
inflating: openocd_compiled/files/openocd/scripts/target/swj-dp.tcl
inflating: openocd_compiled/openocd
inflating: openocd_compiled/files/openocd/scripts/interface/rpi1.cfg
inflating: openocd_compiled/files/openocd/scripts/interface/rpi2.cfg

And here is the output when I run the firmware update within cv:
(cv) pi@dex:~ cd Dexter (cv) pi@dex:~/Dexter bash GoPiGo3/Firmware/gopigo3_flash_firmware.sh
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘auto_detect_rpi’
Unsupported RPi version ‘’. Please report to support@dexterindustries.com
(cv) pi@dex:~/Dexter $

What can I do to help figure this out? And I really do appreciate your assistance.

Rick

Robert,

I was successful in getting GoPiGo3 to run in the virtualenv. I just had to set PYTHONPATH in the virtual environment.
$ export PYTHONPATH=/home/pi/.local/lib/python3.5/site-packages/

and then run the update script:
$ curl -kL dexterindustries.com/update_gopigo3 | bash -s – --user-local --bypass-gui-installation

from the /home/pi/Dexter folder.

Thanks for your help Robert!

Rick Torzynski

Output:
curl -kL dexterindustries.com/update_gopigo3 | bash -s – --user-local --bypass-gui-installation
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 1155 0 --:–:-- --:–:-- --:–:-- 1155
100 178 100 178 0 0 486 0 --:–:-- --:–:-- --:–:-- 486
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
100 11707 100 11707 0 0 10422 0 0:00:01 0:00:01 --:–:-- 10422



Installed /home/pi/.local/lib/python3.5/site-packages/gopigo3-1.2.0-py3.5.egg
Processing dependencies for gopigo3==1.2.0
Searching for spidev==3.4
Best match: spidev 3.4
Adding spidev 3.4 to easy-install.pth file

Using /home/pi/.virtualenvs/cv/lib/python3.5/site-packages
Finished processing dependencies for gopigo3==1.2.0
Installing OpenOCD for GoPiGo3
Archive: openocd_compiled.zip
creating: openocd_compiled/
creating: openocd_compiled/files/
creating: openocd_compiled/files/openocd/
creating: openocd_compiled/files/openocd/scripts/
creating: openocd_compiled/files/openocd/scripts/interface/
creating: openocd_compiled/files/openocd/scripts/target/
inflating: openocd_compiled/files/openocd/scripts/target/at91samdXX.cfg
inflating: openocd_compiled/files/openocd/scripts/target/swj-dp.tcl
inflating: openocd_compiled/openocd
inflating: openocd_compiled/files/openocd/scripts/interface/rpi1.cfg
inflating: openocd_compiled/files/openocd/scripts/interface/rpi2.cfg

pi@dex:~/Dexter/GoPiGo3/Projects/RemoteCameraRobot $ python remote_robot.py
INFO:root:Started recording with picamera
INFO:root:Started stream server for picamera
INFO:root:Starting Flask server
INFO:root:Started Flask web server