repl_python producing errors Reticulate

I am really struggling to get reticulate to work for me.

I ran reticulate::repl_python() and got the normal flag asking me if I wanted to set up a virtual environment. I said yes but now when I run reticulate::repl_python() I get an error:

Error: PyType_GetFlags - /usr/lib64/libpython2.7.so.1.0: undefined symbol: PyType_GetFlags
In addition: Warning message:
In py_initialize(config$python, config$libpython, config$pythonhome, :
   Python 2 reached EOL on January 1, 2020. Python 2 compatability will be removed in an upcoming reticulate relesae.

I found this Posit Communit post on a similar error and followed their advice to reinstall reticulate using devtoolsbut I am still getting the same error.

Reading the git issue chain that was linked to the Posit issue it sounded like I could use use_python to set which python instance to use and that might solve the problem. So then I ran

reticulate::use_python("/bin/python3")
reticulate::repl_python()

And I get out a giant error which then cause my R session to be aborted. Error reads:

[522345:522345:20240502,10581.255126:ERROR process memory_range.cc:86] read of of range
[522345:522345:20240502,10581.255126:ERROR elf_image_reader.cc:558] missing nul-terminator
[522345:522345:20240502,10581.255126:ERROR elf_dynamic_array_reader.h:61] tag not found
.
.
.
[522345:522345:20240502,10581.255126:ERROR elf_dynamic_array_reader.h:61] tag not found
[522345:522345:20240502,10581.255126:ERROR directory_reader_posix.cc:42] opendir: No such file or directory (2)

I am running R 4.2.1, R Studio 2023.12 on a Red Hat 8.4 server.

Updates 1:

  1. I tried reinstalling reticulate that did not help
  2. When I run py_run_string("import sys; print(sys.version)") as a test I get the first PyType_GetFlags error as written above.

Updates 2:

  1. After ignoring this problem for several weeks I have no uninstalled and reinstalled reticulate and now I am getting new behavior
  2. When I run reticulate::py_run_string("import sys; print(sys.version)") I get:
3.6.8 (default, Jun 14 2022, 12:54:58)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]

and when I run reticulate::py_config() I get:

python:         /usr/bin/python3
libpython:      /usr/lib64/libpython3.6m.so
pythonhome:     //usr://usr
version:        3.6.8 (default, Jun 14 2022, 12:54:58)  [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
numpy:           [NOT FOUND]
 
NOTE: Python version was forced by RETICULATE_PYTHON_FALLBACK

so it seems now my instance is recognize and using Python 3.
3. However when I run reticulate::repl_python() I am still getting crazy fatal errors that cause R Studio to abort, see below.


It looks like reticulate is trying to use Python 2. Python 2 is no longer supported.

Do you have a more recent version of Python 3 available? If not, you can call reticulate::install_python().

My best guess is that the second error you see will resolve if you restart the R session; attempting to bind to Python 2 may leave reticulate in an inconsistent state.

I do have Python 3 installed so I am not sure why reticulate isn't calling it?

Never mind it is now calling Python3 but still failing see Update 2 in the main text for more details.

Can you please open an issue in Issues · rstudio/reticulate · GitHub with instructions for how to reproduce the crash? We prioritize fixing segfaults highly and usually fix as soon as we can reproduce.

I actually able to solve my problem by creating a conda environment and running my reticulate python code iniside that conda environment. But I can still report this error on GitHub if you still think it would be useful.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.