Skip to content

Instantly share code, notes, and snippets.

@goobta
Created February 7, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goobta/37b058dcec2e08c89efe10b9323b9d23 to your computer and use it in GitHub Desktop.
Save goobta/37b058dcec2e08c89efe10b9323b9d23 to your computer and use it in GitHub Desktop.
Solo Virtual Environment Bootstrapper

Solo Virtual Environment Bootstrapper

ROS is kind of a hack when it comes to environment sandboxing because it essentially works by monkey-patching your bash environment. Virtual environments are kind of a hack when it comes it environment sandboxing because it essentially works by monkey-patching your bash environment. What are we using? Both.

First Time Use

This script will generate a Python 3.6 virtual environment called venv-ros-solo in the directory that the script is located. Note that means that you need to have python3.6-venv installed. On Debian/Ubuntu variants, this should be pretty easily doable with sudo apt install python3.6-venv.

Note that Python 3.6 is required because ROS 2 dashing depends upon it.

To generate the environment, simply copy setup-venv.sh to the folder that you want to create the venv in and

  1. chmod +x setup-venv.sh
  2. ./setup-venv.sh

Every Time Use

You should now have a virutal environment under the name of venv-ros-solo. However, given how ROS implements its environment patching, you need to source your envs in a specific order. You need to

  1. source the ROS setup script source install/setup.bash
  2. source the venv source venv-ros-solo/bin/activate

If you source the ROS install script first, it will override the virtual environment and your program won't run.

#!/bin/bash
python3.6 -m venv venv-ros-solo
touch venv-ros-solo/COLCON_IGNORE
source venv-ros-solo/bin/activate
pip install -U pip wheel setuptools
pip install git+https://github.com/WPI-MMR/ros2sim.git
echo "export PYTHONPATH=$(pwd)/venv-ros-solo/lib/python3.6/site-packages:\$PYTHONPATH" >> venv-ros-solo/bin/activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment