Python3 with ortools

Python3 with ortools

von ALYSSON FILIPE -
Anzahl Antworten: 3

Hello everyone,

Has anyone managed to run OR-Tools for Python with coderunner?

I installed it in the jobe sandbox. Running directly in the container, it's ok, but running from the moodle plugin, it gives an error:

Ex:

from ortools.linear_solver import pywaplp

TestExpectedGot
print (sqr(-5))
25
***Error***
Traceback (most recent call last):
  File "__tester__.python3", line 1, in <module>
    from ortools.linear_solver import pywaplp
ModuleNotFoundError: No module named 'ortools'

Thanks,

Als Antwort auf ALYSSON FILIPE

Re: Python3 with ortools

von Richard Lobb -

It sounds like the ortools module has been installed in the wrong context, e.g. for a specific user rather than globally, or installed in python2 rather than python3 or installed using the wrong virtual environment, or ... the list goes on. For a cartoon on the chaos that can arise, see https://xkcd.com/1987/

I see that the OR tools page says to install it with

python -m pip install --upgrade --user ortools

However, that won't work because it will install the module only for the current user (root?), and the various job-runner processes jobe0, jobe1, jobe2 etc won't be able to use it

If you haven't already installed a lot of other modules using the apt package manager, and have only one version of python3 installed, the following should work:

sudo -H python3 -m pip install ortools

But if you've installed modules using  apt rather than pip, conflicts can arise.

Als Antwort auf Richard Lobb

Re: Python3 with ortools

von ALYSSON FILIPE -

Hi Richard,

I install using "python3 -m pip install --upgrade --user ortools" on the Dockerfile and building a new image of docker container.

But in fact it is not available in the context of the user jobe, who executes the code from the plugin.

Als Antwort auf ALYSSON FILIPE

Re: Python3 with ortools

von Richard Lobb -

I think the problem is with the --user option, which installs modules for use only by the current user running the command. This makes them unavailable to the jobe user. Try the command without the '--user'.