R reticulate unable to find installed python libra

2020-07-08 06:28发布

问题:

I'm venturing into using Reticulate in R and having trouble installing a package, specifically psycopg2 but I've also tried installing twisted with the same result.

after I load reticulate in R I double check to make sure my package is installed:

> conda_install(envname = "r-reticulate", packages="psycopg2")
Solving environment: ...working... done

# All requested packages already installed.

Looks good. So I set my condaenv to r-reticulate just to be double sure. The docs say I should not have to do this, but it should not hurt:

> use_condaenv( "r-reticulate")

Then I try to import psycopg2:

> psycopg2 <- import('psycopg2')
Error in py_module_import(module, convert = convert) : 
  ImportError: No module named psycopg2

If I install twisted the same way, I get the same error:

> twisted <- import('twisted')
Error in py_module_import(module, convert = convert) : 
  ImportError: No module named twisted

So, what am I doing wrong here?

Below is the output of conda_list and py_config... I was expecting py_config to show me the path to the python exe in my r-reticulate environment. However I don't have anything to compare this to, so my expectations may have been wrong.

> conda_list()
          name                                                                              python
1     Anaconda                     C:\\Users\\jal\\AppData\\Local\\Continuum\\Anaconda\\python.exe
2 r-reticulate C:\\Users\\jal\\AppData\\Local\\Continuum\\Anaconda\\envs\\r-reticulate\\python.exe

> py_config()
python:         C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\python.exe
libpython:      C:/Users/jal/AppData/Local/CONTIN~1/Anaconda/python27.dll
pythonhome:     C:\Users\jal\AppData\Local\CONTIN~1\Anaconda
version:        2.7.15 |Anaconda custom (64-bit)| (default, May  1 2018, 18:37:09) [MSC v.1500 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\lib\site-packages\numpy
numpy_version:  1.14.3
pandas:         C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\lib\site-packages\pandas

python versions found: 
 C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\python.exe
 C:\Users\jal\AppData\Local\CONTIN~1\ANACON~1\python.exe

回答1:

On a whim I downloaded and installed the latest RStudio desktop (1.2.701) and upgraded from 1.1.442. This seems to have solved my issue. The packages load and I now see that when I run py_config I see paths that reflect my environment choice, as I would expect.

> py_config()
python:         C:\Users\jal\AppData\Local\Continuum\Anaconda\envs\r-reticulate\python.exe
libpython:      C:/Users/jal/AppData/Local/Continuum/Anaconda/envs/r-reticulate/python36.dll
pythonhome:     C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\envs\R-RETI~1
version:        3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\envs\R-RETI~1\lib\site-packages\numpy
numpy_version:  1.14.3
psycopg2:       C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\envs\R-RETI~1\lib\site-packages\psycopg2

python versions found: 
 C:\Users\jal\AppData\Local\Continuum\Anaconda\envs\r-reticulate\python.exe
 C:\Users\jal\AppData\Local\CONTIN~1\Anaconda\python.exe
 C:\Users\jal\AppData\Local\CONTIN~1\ANACON~1\python.exe


回答2:

I solved my issue by following this way:

  • Close RStudio.
  • Open Terminal and activate your desired environment.
  • Run RStudio by $ open -na Rstudio

Now you have your anac



回答3:

I solved my issue by following this way in RStudio:

py_config() No non-system installation of Python could be found. Would you like to download and install Miniconda? Miniconda is an open source environment management system for Python. See https://docs.conda.io/en/latest/miniconda.html for more details.

Would you like to install Miniconda? [Y/n]: Y

  • Downloading "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" ... trying URL 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe' Content type 'application/octet-stream' length 57256056 bytes (54.6 MB) downloaded 54.6 MB

  • Installing Miniconda -- please wait a moment ...



标签: r reticulate