"libpython: [NOT FOUND]" for python3.7

python3.7 appears to work outside RStudio, 3.7.4 to be precise
The lib appears to be
/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7.so

However, in RStudio Version 1.2.5001 running R version 3.4.4 (2018-03-15), I get

> library(reticulate)
> py_discover_config()
python:         /home/martin/.virtualenvs/r-reticulate/bin/python
libpython:      [NOT FOUND]
pythonhome:     /usr/local:/usr/local
version:        3.7.4 (default, Oct 12 2019, 20:46:47)  [GCC 5.4.0 20160609]
numpy:          /home/martin/.virtualenvs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version:  1.17.2

python versions found: 
 /home/martin/.virtualenvs/r-reticulate/bin/python
 /usr/bin/python
 /usr/bin/python3
> py_available()
[1] FALSE

Any advice please, for this newbie?

It's a little tricky to configure python 3 on reticulate, try creating a new virtual environment and using use_virtualenv() function.

library(reticulate)
# You just need to make this step once to create the virtualenv
virtualenv_create("py3-virtualenv", python = "/usr/bin/python3")
use_virtualenv("py3-virtualenv")

Thank you, Andres!
The commandyou suggested

> virtualenv_create("py3-virtualenv", python = "/usr/bin/python3")
gives:

Creating virtual environment 'py3-virtualenv' ...
Using python: /usr/bin/python3
New python executable in /home/martin/.virtualenvs/py3-virtualenv/bin/python2
Also creating executable in /home/martin/.virtualenvs/py3-virtualenv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
**Running virtualenv with interpreter /usr/bin/python2**
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting pip
  Using cached https://files.pythonhosted.org/packages/4a/08/6ca123073af4ebc4c5488a5bc8a010ac57aa39ce4d3c8a931ad504de4185/pip-19.3-py2.py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/6a/9a/50fadfd53ec909e4399b67c74cc7f4e883488035cfcdb90b685758fa8b34/setuptools-41.4.0-py2.py3-none-any.whl
Installing collected packages: pip, wheel, setuptools
Successfully installed pip-19.3 setuptools-41.4.0 wheel-0.33.6
> 

I am confused by the line
Running virtualenv with interpreter /usr/bin/python2
and the appropriate deprecation warning.

> use_virtualenv("py3-virtualenv")

runs smoothly.
However in a new R-session, I get

> library(reticulate)
> use_virtualenv("py3-virtualenv")
> py_discover_config()
python:         /home/martin/.virtualenvs/r-reticulate/bin/python
libpython:      [NOT FOUND]
pythonhome:     /usr/local:/usr/local
version:        3.7.4 (default, Oct 12 2019, 20:46:47)  [GCC 5.4.0 20160609]
numpy:          /home/martin/.virtualenvs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version:  1.17.2

python versions found: 
 /home/martin/.virtualenvs/py3-virtualenv/bin/python
 /home/martin/.virtualenvs/r-reticulate/bin/python
 /usr/bin/python
 /usr/bin/python3

> py_available()
 [1] FALSE

It could be my fault because
in /usr/bin, I have

lrwxrwxrwx 1 root root      24 Oct 14 09:10 python -> /usr/local/bin/python3.7
but
lrwxrwxrwx 1 root root      16 Nov 24  2017 python-config -> python2.7-config

From the terminal prompt I do get

/usr/bin$ python
Python 3.7.4 (default, Oct 12 2019, 20:46:47)
[GCC 5.4.0 20160609] on linux

What is the gospel about naming and links?

There is a reticulate issue tracking support for Python 3 when Python 2 is also present.

Do you get any different outcome if you create the virtual environment with a system call instead?

library(reticulate)
system("virtualenv -p /usr/bin/python3 /home/martin/.virtualenvs/py3-virtualenv")
use_virtualenv("py3-virtualenv")

Thank you, but the answer is "no change", I am afraid.

library(reticulate)
virtualenv_create("py3-virtualenv", python = "/usr/bin/python3")
virtualenv: py3-virtualenv
use_virtualenv("py3-virtualenv")
py_available()
[1] FALSE

system("virtualenv -p /usr/bin/python3 /home/martin/.virtualenvs/py3-virtualenv")
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/martin/.virtualenvs/py3-virtualenv/bin/python3
Not overwriting existing python script /home/martin/.virtualenvs/py3-virtualenv/bin/python (you must use /home/martin/.virtualenvs/py3-virtualenv/bin/python3)
Installing setuptools, pkg_resources, pip, wheel...done.
use_virtualenv("py3-virtualenv")

py_discover_config()
python: /home/martin/.virtualenvs/r-reticulate/bin/python
libpython: [NOT FOUND]
pythonhome: /usr/local:/usr/local
version: 3.7.4 (default, Oct 12 2019, 20:46:47) [GCC 5.4.0 20160609]
numpy: /home/martin/.virtualenvs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version: 1.17.2

python versions found:
/home/martin/.virtualenvs/py3-virtualenv/bin/python
/home/martin/.virtualenvs/r-reticulate/bin/python
/usr/bin/python
/usr/bin/python3

py_available()
[1] FALSE

At the linux commandline, I can invoke
/home/martin/.virtualenvs/r-reticulate/bin/python
succesfully..

Any other ideas?

This is weird, I also get FALSE

library(reticulate)
use_virtualenv("py3-virtualenv")
py_available()
#> [1] FALSE

But after running a python code chunk (which runs with the right python version)

```{python}
import sys
print (sys.version)
```
#> 3.6.8 (default, Oct  7 2019, 12:59:55) 
#> [GCC 8.3.0]

If I run py_available() again, I get TRUE

py_available()
#> [1] TRUE

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