9

I am trying to import a python module in R using the reticulate package. The module can be found here. I cloned the repository and ran python setup.py install which ran successfully. If I open a python shell, I'm able to import debot. However, when I try to import it in RStudio, I get the following error:

dbot=import("debot")
Error in py_module_import(module, convert = convert) : 
  ImportError: No module named debot

I am on macOS Sierra version 10.12.6 and installed python 3.6 through Anaconda. I have also tried giving the path to python as:

path_to_python <- "/anaconda/bin/python3.6"
use_python(path_to_python)

When I run python from a terminal, I get:

Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Not sure if the path to python is correct.

Ok, did some more digging around and discovered that reticulate still refers to my older python path for python 2.7 which came as default with my Macbook. When I run py_config(), this is what I get:

python:         /usr/bin/python
libpython:      /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome:     /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version:        2.7.10 (default, Feb  7 2017, 00:08:15)  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]

No matter what I try but I can't get reticulate to look at the correct path where the module has been installed using the use_python() function. I do believe this is an issue with reticulate. Any ideas what my next steps should be?

Dhiraj
  • 1,650
  • 1
  • 18
  • 44
  • I'm not familiar with this package but I assume you did `library(reticulate)` and have read the relevant doc at `?import` ? Also, are you able to import other python modules, including non-pip ones? Is it just this module that is the problem? – C8H10N4O2 Aug 24 '17 at 12:03
  • Yes I did. In fact I faced no problems while running my script on Windows. I think its a Mac issue, or the python installation which ships with it as default. – Dhiraj Aug 24 '17 at 12:05
  • OK, looks like a good question, sorry I got nothin... – C8H10N4O2 Aug 24 '17 at 12:06
  • 1
    If it helps, `which python` reveals `/anaconda/bin/python` and hence changed `path_to_python <- "/anaconda/bin/python"` but the result is the same. – Dhiraj Aug 25 '17 at 05:01
  • Also when I run `python setup.py install`, it shows me `Installed /anaconda/lib/python3.6/site-packages/debot-0.1-py3.6.egg` – Dhiraj Aug 25 '17 at 05:05

1 Answers1

12

After reading this I finally figured out. I think before calling any other function from the reticulate package, it is imperative to specify the path to python to use. Hence the order I am following now is:

library(reticulate)
path_to_python <- "/anaconda/bin/python"
use_python(path_to_python)
Dhiraj
  • 1,650
  • 1
  • 18
  • 44
  • 3
    Dhiraj I am also having same issue. But even with use_python command it is still picking up the default system python. Any comments? – user2906657 May 14 '18 at 05:52
  • 1
    I too am having the same problem and use_python is not working. – Cyrus Mohammadian Jan 01 '19 at 18:56
  • 1
    similar for me, then I realised my problem was that I ran py_config() first to check which one is loaded, but this command actually loads the default interpreter. so do not run this. the first thing has to be reticulate::use_python(path). hope that helped – Fitzroy Hogsflesh Oct 09 '19 at 21:40
  • I had the same problem. I restarted my R session and then it worked. Go figure? – Seanosapien Sep 29 '22 at 13:15