1

Im attempting to use the numpy module in webots but whatever I try I always get

INFO: assignment_2_controller_2: Starting controller: python3.6 -u "assignment_2_controller_2.py" 
[assignment_2_controller_2] Traceback (most recent call last):
[assignment_2_controller_2]   File "assignment_2_controller_2.py", line 4, in <module>
[assignment_2_controller_2]     import numpy
[assignment_2_controller_2] ModuleNotFoundError: No module named 'numpy'
WARNING: 'assignment_2_controller_2' controller exited with status: 1.

I have installed numpy with both pip2 and pip3 and neither seem to have made any difference and the package shows up in ~/.local/lib/python3.6/site-packages. I can also confirm that this module works in the python editor and in other python files. Is there perhaps something I need to change in webots python Makefile or perhaps in my environment variables?

Edit: Printing sys.path shows

'/snap/webots/14/usr/share/webots/lib/controller/python36', '/snap/webots/14/usr/lib/python36.zip', '/snap/webots/14/usr/lib/python3.6', '/snap/webots/14/usr/lib/python3.6/lib-dynload', '/snap/webots/14/usr/lib/python3/dist-packages'

I installed webots using snap but why wouldnt it use the python dictated by the PATH environment variable?

Fix: By the looks of it snap creates a contained filesystem for webots to run in by design in which it installed its own python binaries. I therefore uninstalled webots with snap and then installed from the .deb file off their website and now it works fine.

  • 1
    You could print `sys.path` to see if your python is using those directories. – tdelaney May 12 '20 at 21:06
  • what may also keep you from importing it: If you installed it from your regular user with pip but `sudo` run the app (or the other way round), that could be the reason – finnmglas May 12 '20 at 21:08
  • @tdelaney Ahh interesting, sys.path shows `'/snap/webots/14/usr/share/webots/lib/controller/python36', '/snap/webots/14/usr/lib/python36.zip', '/snap/webots/14/usr/lib/python3.6', '/snap/webots/14/usr/lib/python3.6/lib-dynload', '/snap/webots/14/usr/lib/python3/dist-packages'` How can I change that from using the /snap/... path to using the system path? – Champgoblem2 May 12 '20 at 21:10
  • Looks like you are using a different python. I should have mentioned printing `sys.executable` – tdelaney May 12 '20 at 21:19
  • I don't know webots so can't say much about how things are supposed to be installed. – tdelaney May 12 '20 at 21:21
  • sys.executable shows `/snap/webots/14/usr/bin/python3.6` so by the looks of it, it is using the python installed by webots? – Champgoblem2 May 12 '20 at 21:21

1 Answers1

1

Webots installed from the Snap package is running in a kind of sandbox, it is therefore using the version of Python distributed with the snap package (which you can't alter).

As explained in the documentation, you might use external controllers to launch yourself the controller instead of letting Webots starting it. This way you can chose which version of Python you want to use: https://cyberbotics.com/doc/guide/installation-procedure#installing-the-snap-package

Alternatively, you can use a different way to install Webots (from the Debian or archive package). The other installations are not coming with Python and are using the system Python.

David Mansolino
  • 1,713
  • 7
  • 13
  • 1
    Yeah thats the same conclusion I came to, I ended up uninstalling with snap and reinstalling it via the deb file provided on their site – Champgoblem2 May 13 '20 at 14:35