ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to use a Jupyter Notebook with Colcon?

asked 2023-07-27 15:55:16 -0500

ari-reframe gravatar image

I've got a problem that I suspect is easy, but I absolutely can't figure out---any advice is much appreciated.

Here's the situation: I have a standard ROS2/Colcon Python package (ie. basically fresh out of ros2 pkg create, built with ament_python). This package contains various Python files used in production.

In addition, for prototyping purposes, I'd like to add a Jupyter notebook. I need the notebook to be able to import other files in the package and its dependencies. I don't care if the notebook is included in the build output or not. I don't mind running a build once (or if dependencies change), but I'd really like to avoid re-building every time I change the notebook or an imported file.

I've tried various approaches involving modifications to sys.path inside the notebook, but I haven't been able to get anything to work. I think the --symlink-install flag to colcon build might also be helpful, but I'm not sure exactly how.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-07-28 11:01:05 -0500

ari-reframe gravatar image

Alright, turns out the problem was indeed easy. I was running my Jupyter Notebook from VS Code's built-in editor, which by default spawns its own Jupyter server.

However, sourcing the colcon workspace overlay sets $PYTHONPATH such that Python can properly find colcon's packages. Starting the server from VS Code doesn't inherit that env var.

It turns out the answer is simple: just start the notebook server from the terminal and have VS Code connect to it. Problem solved!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-07-27 15:55:16 -0500

Seen: 141 times

Last updated: Jul 28 '23