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.
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
chmod +x setup-venv.sh
./setup-venv.sh
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
- source the ROS setup script
source install/setup.bash
- 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.