0

I used Drake Binary Installation for Python from this site https://drake.mit.edu/python_bindings.html#installation

Then when i checked to ensure I can import pydrake, I have got this:

dmitriy@dmitriy-Lenovo-ideapad-310-15ISK:/opt$ python3 -c 'import pydrake.all; print(pydrake.__file__)'
/opt/drake/lib/python3.8/site-packages/pydrake/__init__.py

But when I try execute this example:

import pydrake.all

builder = pydrake.systems.framework.DiagramBuilder()
plant, _ = pydrake.multibody.plant.AddMultibodyPlantSceneGraph(builder, 0.0)
pydrake.multibody.parsing.Parser(plant).AddModelFromFile(
  pydrake.common.FindResourceOrThrow(
      "drake/examples/pendulum/Pendulum.urdf"))
plant.Finalize()
diagram = builder.Build()
simulator = pydrake.systems.analysis.Simulator(diagram)

I get this:

No module named 'pydrake'

1 Answers1

0

The documentation you cite shows how to export PYTHONPATH (or alternatively, how to us a virtualenv). Since the first command you posted works, you must have done those steps correctly. Thus, the second command should have also worked.

Maybe you ran the second command in a new terminal, without the correct environment set up?

jwnimmer-tri
  • 1,994
  • 2
  • 5
  • 6
  • Thanks, It worked in the same terminal as you said. But now new quations have appered: 1. Can I somehow use this pydrake without writing this command at every new terminal session ? python3 -c 'import pydrake.all; print(pydrake.__file__)' 2. As I like to use Visual Studio Code, can I carefully use pydrake with jupyter notebook in VSC ? – Dmitriy Ogureckiy Sep 15 '21 at 20:30
  • The important command isn't the "print", it's the above `export PYTHONPATH=...` line. As long as you do "export" in the terminal you're using to launch jyputer, you should be fine. It's a standard convention of Python, not anything Drake specific. – jwnimmer-tri Sep 15 '21 at 23:22
  • Thank you, but does some ability exist for don't writing `export PY...` at every new terminal session ? – Dmitriy Ogureckiy Sep 25 '21 at 19:24