Skip to content

Incorrect Python version used when importing controller? #3925

Closed

Description

@Olegas

Describe the Bug
When starting a world with Python controller used, it failed with the following error

INFO: referee: Starting controller: /usr/local/Cellar/python@3.9/3.9.8/bin/python3.9 -u referee.py
Traceback (most recent call last):
  File ".../controllers/referee/referee.py", line 14, in <module>
    from controller import Supervisor, AnsiCodes, Node
  File "/Applications/Webots.app/lib/controller/python39/controller.py", line 31, in <module>
    import _controller
ImportError: dlopen(/Applications/Webots.app/lib/controller/python39/_controller.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.9/Python
  Referenced from: /Applications/Webots.app/lib/controller/python39/_controller.so
  Reason: image not found
WARNING: 'referee' controller exited with status: 1.

I've found in /Applications/Webots.app/lib/controller there are folders python39 and python39_brew. So, I guess they are for system's bundled Python and one installed with Homebrew.

If I remove the python39 folder contents and instead of it put the one from python39_brew folder, my world starts successfully without any errors.

In the webots settings python is set to exact location on Homebrew Python 3.9 - /usr/local/Cellar/python@3.9/3.9.8/bin/python3.9

So, webots somehow uses incorrect include paths or something?

System

  • macOS BigSur
  • Python 3.9 from Homebrew
  • Webots 2021b

Activity

  1. Olegas commented on Nov 16, 2021

    @Olegas
    ContributorAuthor

    I've found the detection code here:

    QProcess process;
    process.setProcessEnvironment(env);
    process.start(mPythonCommand, QStringList() << "-c"
    << "import sys; print(sys.exec_prefix);");
    process.waitForFinished();
    const QString output = process.readAll();
    if (output.startsWith("/usr/local/Cellar"))

    If I execute the command webots are searching for Python path with, it gives me the following result:

    $ /usr/local/Cellar/python@3.9/3.9.8/bin/python3.9 -c 'import sys; print(sys.exec_prefix)'
    /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9
    
  2. omichel commented on Nov 17, 2021

    @omichel
    Member

    Do you have any idea on how this could be fixed?

  3. Olegas commented on Nov 17, 2021

    @Olegas
    ContributorAuthor

    What if we compare against /usr/local/Cellar not a sys.exec_prefix but a mPythonCommand.
    So, at least one can supply a full path to settings to fix this issue.
    But I still think this is not a general solution, sort of a hotfix (

  4. omichel commented on Nov 17, 2021

    @omichel
    Member

    That seems to be a pretty good solution, as in any case we already have "/usr/local/Cellar" hard-coded in there. May I let you go ahead with a PR implementing this fix?

  5. omichel commented on Nov 17, 2021

    @omichel
    Member

    @Olegas: I just sent you an invite to become a member of the Webots committers so that you don't need to fork this repository to propose a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions