Forums

RuntimeError: implement_array_function method already has a docstring since March 2020

My students repeatedly get this "RuntimeError: implement_array_function method already has a docstring" (only since this month), upon importing either numpy or scipy or anything from these libraries. It makes the site practically unusable for them. I read older bug reports on this. In one of these it said that this happens with 3.7 and "downgrading to 3.6" would resolve the issue. (It seems a serious and old numpy issue https://github.com/numpy/numpy/issues/665 that affects systems where python it run from within a "wrapper" / subinterpreter. [I apologize for approximate terminology.]) Now I'm running 3.7 and personally don't have the problem. So I suspect that my students who created their account in this semester (2020) might have 3.8 by default and that's why they get the error and I don't. So my question: how can they specify that their .py files be run with python3.7 (or 3.6 or ...) ?

The problem you're seeing is actually caused by the version of NumPy that's installed rather than the version of Python. The most recent version of NumPy has a bug that means it generates that error if it's imported twice in the same process.

There are two workarounds:

  • Kill the process between runs. So, if you're using our in-browser editor, the first run will work; before running it a second time, exit the console at the bottom of the screen using control-D or the exit() command. Then the next run will start a fresh console, and it will work again.
  • Switch to an earlier version of NumPy that doesn't have this bug. Your students can do this yourselves by using pip3.8 install with the --user flag and a version number. Alternatively, if they are all set up with your account as their teacher from the Account page, we could change their accounts so that they use our old "earlgrey" system image instead of our most recent one, "fishnchips" -- that would downgrade the pre-installed numpy (and also remove Python 3.8).

Thank you for your reply. The first option did not really work: the file seems to run without error but subsequently the imported libraries are not available, so you cannot call the functions defined in the file from within the console. (If you use e.g. "import scipy.interpolate as interp" in the file and interp.lagrange() in some function, then trying to call that function will yield an error "interp is not defined".) So only the second option would work; since I can't test I'd like to know more details concerning the comment to issue (esp. version number). Unfortunately the student's accounts aren't linked to mine yet.

However, I found the answer to my last question in that a shebang #!/path/python3.7 would run the file (and console!?) in 3.7, wouldn't that use an earlier version of numpy, too?

All versions of python3 have tha same version of numpy pre-installed. See https://www.pythonanywhere.com/batteries_included/

We can upgrade your account to a newer system image so you have the same versions as newly created accounts.

One word of warning first -- because changing the system image upgrades a lot of the pre-installed Python packages, any code that you have that relies on those packages might break if it's not compatible with the new versions. Also, because the new image has newer versions of Python, if you have any virtualenvs, you may need to rebuild them. If you're happy to go ahead despite that, just let us know and we'll switch you over.

I'm affraid I'm having the same problem. The script works on my computer but I get:

Traceback (most recent call last): File "/home/sebastienc/fmpcloud/fundamentals_json.py", line 6, in <module> import pandas as pd File "/usr/lib/python3.8/site-packages/pandas/init.py", line 11, in <module> import(dependency) File "/usr/lib/python3.8/site-packages/numpy/init.py", line 142, in <module> from . import core File "/usr/lib/python3.8/site-packages/numpy/core/init.py", line 17, in <module> from . import multiarray File "/usr/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module> from . import overrides File "/usr/lib/python3.8/site-packages/numpy/core/overrides.py", line 16, in <module> add_docstring( RuntimeError: implement_array_function method already has a docstring

Anytime I am importing Pandas.

Do you have a solution for that?

Best,

Sebastien

Yes, we have a solution. It's in the second post in this thread. There's actually also another option and that is to not: use the editor to edit your code, but run it in a console that you keep open in a different tab. Then you're starting a new process for every run and you will not encounter the bug.

I just want to say I had this same issue with loading pandas (maybe numpy to). I had a bash console open and the editor open. After closing the editor and in the bash console running >> python3 script_name.py it ran just fine. Kind of annoying but tolerable because i develop before running it on the server.

Hi, I am having the same issue as OP when I import pandas. Have tried both the workarounds you suggested. Would it be possible for you to change my account so it uses the older system image when this error wasn't occuring?

Thanks, Sam

Ok. I have set your account to an older system image.

I have the same error with Pandas.. anyhelp please?

Did you try solution proposed by Giles earlier in this thread: https://www.pythonanywhere.com/forums/topic/26966/#id_post_77021 ?

I try to use the exit() command and else but not working.. but I can't Switch to an earlier version to pandas?

Could you post a screenshot showing what happens when it doesn't work? The older version of Pandas wouldn't be a good solution, because the newer ones have lots of improvements.

this the screenshot:

https://ibb.co/hW3VF3P

I can see the expected error on your screenshot. Do you kill the process between runs as in Giles solution above, that Glenn linked to?

yes I using exit() command and not working

You did exit() in the console after the run and re-run the script?

Yes, check this pictures

https://ibb.co/m6Yt24g

Using exit in your script will not work, you need to run it at the ">>>" prompt after your script has run.