How to build ROS environment using Python3

Hi there
I have just started ROS lesson in this class.
I have a ROS learning environment on Ubuntu on my PC, but I haven’t built an environment to use Python3 with ROS.
I want to make Python3 ROS environment on my PC as well as this online environment. What should I do? For example, I want to solve the problem that the Python path does not pass when using Anaconda or pyenv.

Best Gegards

I’m writing an article indicating step by step how to do it. Please give me a few days to have it published and come back to you. It will be ready along this week.

1 Like

Thank you , rtellez !

Any help would be appreciated.

1 Like

Hello!
I managed to build ROS with Python3 environment.
and tried to run the cartpole like online cource " OpenAI with ROS",
however errors have occurred as follows.

So,I tried to install rospkg with pip3 but couldn’t on vertual (openai_venv).

Any suggestions?

=========================================================================

(openai_venv) kxrn14@kxrn14:~$ roslaunch my_cartpole_training start_training.launch
... logging to /home/kxrn14/.ros/log/20dce552-31bc-11ea-8532-d8fc93353d1f/roslaunch-kxrn14-11874.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/loader.py:409: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  data = yaml.load(text)
started roslaunch server http://kxrn14:45982/

SUMMARY
========

PARAMETERS
 * /cartpole_v0/alpha: 0.5
 * /cartpole_v0/control_type: velocity
 * /cartpole_v0/epsilon: 0.1
 * /cartpole_v0/epsilon_discount: 0.999
 * /cartpole_v0/gamma: 0.9
 * /cartpole_v0/init_pos: 0.0
 * /cartpole_v0/max_base_pose_x: 2.5
 * /cartpole_v0/max_base_velocity: 50
 * /cartpole_v0/max_pole_angle: 0.7
 * /cartpole_v0/min_base_pose_x: -2.5
 * /cartpole_v0/min_pole_angle: -0.7
 * /cartpole_v0/n_actions: 4
 * /cartpole_v0/nepisodes: 1000
 * /cartpole_v0/nsteps: 1000
 * /cartpole_v0/number_splits: 10
 * /cartpole_v0/pos_step: 0.016
 * /cartpole_v0/running_step: 0.04
 * /cartpole_v0/wait_time: 0.1
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES
  /
    cartpole_gym (my_cartpole_training/start_training.py)

auto-starting new master
process[master]: started with pid [11884]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 20dce552-31bc-11ea-8532-d8fc93353d1f
process[rosout-1]: started with pid [11897]
started core service [/rosout]
/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/packages.py:451: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if resource_name in files:
process[cartpole_gym-2]: started with pid [11914]
Traceback (most recent call last):
  File "/home/kxrn14/catkin_ws/src/my_cartpole_training/start_training.py", line 12, in <module>
    import rospy
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named 'rospkg'
[cartpole_gym-2] process has died [pid 11914, exit code 1, cmd /home/kxrn14/catkin_ws/src/my_cartpole_training/start_training.py __name:=cartpole_gym __log:=/home/kxrn14/.ros/log/20dce552-31bc-11ea-8532-d8fc93353d1f/cartpole_gym-2.log].
log file: /home/kxrn14/.ros/log/20dce552-31bc-11ea-8532-d8fc93353d1f/cartpole_gym-2*.log
^C[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done
(openai_venv) kxrn14@kxrn14:~$

Hello again!
However I could install rospack successfully, another error was occurred.

==========================================================================

(openai_venv) kxrn14@kxrn14:~/catkin_ws$ roslaunch my_cartpole_training start_training.launch

NODES
  /
    cartpole_gym (my_cartpole_training/start_training.py)

auto-starting new master
process[master]: started with pid [2907]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 63d47378-31eb-11ea-a388-d8fc93353d1f
process[rosout-1]: started with pid [2920]
started core service [/rosout]
/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/packages.py:451: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if resource_name in files:
process[cartpole_gym-2]: started with pid [2937]
Traceback (most recent call last):
  File "/home/kxrn14/catkin_ws/src/my_cartpole_training/src/start_training.py", line 17, in <module>
    import my_cartpole_task_env
  File "/home/kxrn14/catkin_ws/src/my_cartpole_training/src/my_cartpole_task_env.py", line 13, in <module>
    timestep_limit=1000,
  File "/home/kxrn14/catkin_ws_python3/openai_venv/lib/python3.5/site-packages/gym/envs/registration.py", line 153, in register
    return registry.register(id, **kwargs)
  File "/home/kxrn14/catkin_ws_python3/openai_venv/lib/python3.5/site-packages/gym/envs/registration.py", line 147, in register
    self.env_specs[id] = EnvSpec(id, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'timestep_limit'
[cartpole_gym-2] process has died [pid 2937, exit code 1, cmd /home/kxrn14/catkin_ws/src/my_cartpole_training/src/start_training.py __name:=cartpole_gym __log:=/home/kxrn14/.ros/log/63d47378-31eb-11ea-a388-d8fc93353d1f/cartpole_gym-2.log].
log file: /home/kxrn14/.ros/log/63d47378-31eb-11ea-a388-d8fc93353d1f/cartpole_gym-2*.log

It is easier to run ros on python 2 and openai in python 3. in 2 different virtual environments

Hi @ts_alfa155sportiva ,

did you manage to make ROS work on the python3 environment?

Hello! ralves

No much more,not yet

Not yet created the text. We have scheduled though a ROS Developers Live Class for the 11th February about how to set up your ROS environment with Python 3. We will teach there how to do it live, so you can practice with us during the class

2 Likes

Thank you , rtellez !
I’m looking forward to taking that class!

1 Like

This is fantastic news! Thank you.

1 Like

Hi
good news indeed!
How can we link to the class?
Thanks

1 Like

Hi @joecarmignani,

Thanks for asking. You can find a link to the classes from the ROS Developers Live Class page. You might want to use the save to calendar button to set a reminder for the events.


By the way, welcome to the Community!

1 Like

Hi - When I checked the schedule, the Python3 class doesn’t seem to be listed for Feb 11th. Is it still planned?

1 Like

Thanks for letting us know about that. Apologies for the confusion. The schedule has been updated.

Hello,
I attended the live class on this subject and have been trying to replicate the directions given on my own computer. If I have sourced ros/melodic as installed on my computer, I can compile the catkin_make command with no problem, but if I try to start from a new terminal, as in the second step, only sourcing the build and python virtual env, I keep getting the error:
“Traceback (most recent call last):
File “/opt/ros/melodic/bin/catkin_make”, line 12, in
from catkin.init_workspace import init_workspace
ImportError: No module named catkin.init_workspace”
If I try to compile using ros/melodic, I get the following error:
“CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find PythonInterp: Found unsuitable version “1.4”, but required
is at least “2” (found
/home/CYBERNET/ewills/gazebo_sims/alexnet_demo_py/vcaml_py3/bin/python)”
Can you suggest what I may be missing?
Thank you!

It seems to work, however, if I use catkin build. Anyone have any idea as to why?

Hi Elizabeth,
can you post here the sequence of commands you launch and the response from the terminal. I would like to help on that

Hello!
Thanks for reaching out. I have been mainly following the instructions in the rosjet. So I have created a python3 virtualenv, and installed the necessary packages as listed (catkin tools etc). I sourced this environment and git cloned the dependencies and code I wanted to run.
Then I went back to the workspace and ran “catkin_make -DPYTHON_EXECUTABLE:FILEPATH=/home/user/python3_ws/py3venv/bin/python” (with my own personal paths)
This always works.
Then I kept following the instructions, where you open a new terminal, source the virtualenv and the build, then delete the build and devel folders, and try recompiling with the same catkin_make command. This is what always fails and gives the above error.

I also just noticed when trying to run the code that maybe the catkin build method isn’t foolproof either, as I’m running into errors generated by this (I believe from experience it’s a py2 vs py3 error)

 "File "/home/CYBERNET/ewills/gazebo_sims/alexnet_demo_py3/devel/lib/python2.7/dist-packages/tf2_py/_
_init__.py", line 34, in <module>   
  exec(__fh.read())
  File "<string>", line 38, in <module>
ImportError: dynamic module does not define module export function (PyInit__tf2)"  so clearly python2.7 is working its way in somewhere.

Thanks! I know this is hard to debug on separate systems.

…somehow I did it over and over again and fixed it. Which doesn’t help, but there you go.

1 Like