Python3 creating it's own environment. Why?

Respected Sir, Would you please clear the queries I have:

  1. source ~/.py3venv/bin/activate creates virtual environment. What does it mean to say that we are creating our own environment for python? And what kind of interference would occur with other environments if we don’t create python’s own environment?
  2. source ~/.catkin_ws_python3/devel/setup.bash creates ROS special workspace. Why trouble occurs when we don’t create ROS special workspace. Is it coming in the course to learn to create ROS’s special workspace to be able to work with Python

Hello @abdulbasitisdost,

This is explained at the beginning of Unit 2, Python Basics. Basically, all this is required in order to work with Python 3 in ROS (by default, ROS Kinetic supports Python 2.7).

Best,

Yeah Sir, I got that. I understood, Respected Professor, from Unit 2 that the 1st code is for creating our own environment. It’s because we don’t want it to interfere with other environments. But my question basically was that: Why would interference occur when we don’t create our own environment? and What kind of interference can occur. Would you please elaborate this point?
Secondly I also understood the second code but my question basically was that why can it not work without creating ROS special workspace. And how would I learn creating ROS special workspace?

Hi @abdulbasitisdost,

Let me try to answer your questions:

Why would interference occur when we don’t create our own environment? and What kind of interference can occur? Would you please elaborate this point?

The .py3venv environment contains python libraries compiled for python3. If you don’t source that environment when running your program, the system would import libraries from python2, and at some point, things would just not work. When you source, you can see that the LD_LIBRARY_PATH, ROS_PACKAGE_PATH, and PYTHONPATH variables are changed. You can see that by running env | grep PYTHONPATH before and after sourcing a workspace.

Why trouble occurs when we don’t create ROS special workspace. Is it coming in the course to learn to create ROS’s special workspace to be able to work with Python

When you run ROS commands like rosrun or roslaunch, for example, ROS checks the ROS_PACKAGE_PATH environment variable. It only finds packages if they are located in the workspaces listed in ROS_PACKAGE_PATH. That is why we need a ROS Workspace in order to work with ROS. When you source workspace/devel/setup.bash, the variables aforementioned are set and everything works nicely.

Please let us know if you have any further questions. If the questions are of another subject, feel free to open a new question.

1 Like