Description
Hi
I'm using Mac OS 10.13.6 and I installed Python 3.7.1 by using pyenv. I already switched to that version by pyenv global 3.7.1
. So it returns 3.7.1 when I check by $ python --version
and returns two Python directories namely '/Users/tampm/.pyenv/shims/python' and '/usr/bin/python' when I run $ which -a python
.
But unfortunately, when I call py_available() method on R console, it always returns FALSE although I can see two Python directories mentioned above when I call py_discover_config() method.
Would anyone mind helping me to solve that issue?
Update if I try to call import a Python library on R console and call py_available() method again, it returns TRUE. I did
library(reticulate)
os <- import("os")
os$listdir(".")
It is quite wierd, isn't it? Did I do something wrong in my Python installation?
Thanks
Activity
ghuls commentedon Nov 16, 2018
We also experienced the same problem:
py_available() always returns FALSE
with R and python on Clearlinux.
The problem is that on Clearlinux LIBDIR is set to
/usr/lib
while libpython is located in/usr/lib64
I temporarily fixed it with this by hardcoding the value:
reticulate/inst/config/config.py
try: import sysconfig if not platform.system() == 'Windows': + sysconfig._CONFIG_VARS['LIBDIR'] = '/usr/lib64' sys.stdout.write('\nLIBPL: ' + sysconfig.get_config_vars('LIBPL')[0]) sys.stdout.write('\nLIBDIR: ' + sysconfig.get_config_vars('LIBDIR')[0]) sys.stdout.write('\nPREFIX: ' + sysconfig.get_config_vars('prefix')[0]) sys.stdout.write('\nEXEC_PREFIX: ' + sysconfig.get_config_vars('exec_prefix')[0]) except Exception: pass
The code in JuliaPy (on which this was based according to https://github.com/rstudio/reticulate/blob/24805aa1af2a6e59d22c5e088f2c358fff9e2b3b/inst/config/config.py) works correctly (finds the library in LD_LIBRARY_PATH):
https://raw.githubusercontent.com/JuliaPy/PyCall.jl/master/deps/find_libpython.py
MTamPham commentedon Nov 25, 2018
Apologize but I can't catch you. Do you mean that you're using Clear Linux OS and you fixed the problem manually by adding the
LIBDIR = "/usr/lib64"
inreticulate/inst/config/config.py
?Can you show me where the config.py is? I don't use JuliaPy and I'm new to Python as well.
ghuls commentedon Nov 28, 2018
The following should give the base dir of the reticulate package:
Then find libpython3.7:
find / -name 'libpython3.7*'
protodonata commentedon Dec 3, 2018
Sorry that I am new to everything.
I am also facing the same problem. My Mac is using 2.7 (the very original one). How can I find the path of the python? Should I install the latest by the way?
Many thanks.
mnr commentedon Feb 12, 2019
I'm trying to trace this down. Here's what I find...
py_available()
returns falsepy_discover_config()
debug(py_available)
py_available(initialize = TRUE)
gets toensure_python_initialized()
which returns:removes the error related to Py_CompileString, but
py_available()
still returns FALSEensure_python_initialized
!is_python_initialized()
returns TRUE and we go into the if... statement!is.null(.globals$delay_load_module)
returns FALSEinitialize_python(required_module, use_environment)
returns:Question: Should the parameters to initialize_python be defined as something? Why are they just listed in the function call without some sort of "=" ?
step into
initialize_python()
. (Note thatconfig$numpy$version < "1.6"
returnslogical(0)
. Was it expecting FALSE?)step into
py_initialize(config$python, config$libpython, config$pythonhome, config$virtualenv_activate, config$version >= "3.0", interactive(), numpy_load_error)
Here is a dump of the variables being passed to py_initialize...
invisible(.Call(
_reticulate_py_initialize, python, libpython, pythonhome, virtualenv_activate, python3, interactive, numpy_load_error))
... and we exit py_available with return FALSE
ncoppersmith-r7 commentedon Oct 18, 2019
I'm not sure what the difference is, but I was experiencing this issue using Python 3.8 on Windows 10. I was able to solve it by installing Anaconda for Windows and changing my Sys.setenv(RETICULATE_PYTHON = PATH) to use Anaconda python instead of the regular python binary. Not sure what the underlying issue is, but it would appear that reticulate just doesn't like standard python on Windows.
Jiefei-Wang commentedon Nov 15, 2019
I have the same issue using Python 3.8 on Windows 10. Everything is newly installed, so it is not caused by outdated software. I will try @ncoppersmith-r7 's suggestion. Please fix it...
kevinushey commentedon Nov 15, 2019
It would help if you shared the error you were seeing.
kevinushey commentedon Nov 15, 2019
Here's what I see with the CRAN version of
reticulate
:And with the development version of
reticulate
:Assuming that you're seeing the same issue, this is fixed in the development version of
reticulate
. Hopefully we'll be able to push an update to CRAN by the end of the year.Landau1994 commentedon Dec 3, 2019
try use python 3.6 instead, it works for me
setgree commentedon Jul 14, 2020
Have this issue as well. R 4.0, Python 3.7, miniconda3 recently installed, OS X Catalina
Prelim note: my
.Rprofile
for this project consists of:I'm running the following code:
Finally fixed this by running
py_available(initialize = TRUE)
(got a warning mesage about it requesting the python in the r-reticulate environment but using the python in the regular environment.Anyway I figured it out -- maybe this is something documentation could focus on? I notice the video on the Rstudio website focuses on virtualenv but a lot of the actual reticulate functions focus on conda... thanks for all your help!
304243504 commentedon Sep 20, 2021
@setgree That worked for me, really appreciate it!
conda_python()
point to unexpected Python directory #1480