Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue when using the MongoClient of the PyMongo package #81

Closed
mlampros opened this issue Jul 15, 2017 · 6 comments
Closed

issue when using the MongoClient of the PyMongo package #81

mlampros opened this issue Jul 15, 2017 · 6 comments

Comments

@mlampros
Copy link

mlampros commented Jul 15, 2017

First of all thank you for the useful package.

I face the following problem when trying to call the MongoClient() module from within an R-session,

reticulate::py_module_available("pymongo")

[1] TRUE
PyMng = reticulate::import("pymongo")
init_pym = PyMng$MongoClient(host = 'localhost', 27017L)
Error: attempt to apply non-function

Normally, I receive this error only if the module is not available, however the PyMongo package is installed in my default python version,

Python 3.5.2 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> clt = pymongo.MongoClient(host='localhost:27017')
>>>
> reticulate::py_discover_config(required_module = "pymongo")
python:         /usr/bin/python
libpython:      /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so
pythonhome:     /usr:/usr
version:        3.5.2  [GCC 5.4.0 20160609]
numpy:          /usr/local/lib/python3.5/dist-packages/numpy
numpy_version:  1.12.1
pymongo:        /usr/local/lib/python3.5/dist-packages/pymongo

python versions found: 
 /usr/bin/python
 /usr/bin/python3

I'm also able to open a mongo session and do queries using an ubuntu console,

$ sudo mongod --dbpath /var/lib/mongodb

[sudo] password for lampros: 
2017-07-15T09:39:21.955+0300 I CONTROL  [initandlisten] MongoDB starting : pid=4535 port=27017 dbpath=/var/lib/mongodb 64-bit host=lampros-MS-7640
.....
$ mongo
MongoDB shell version: 3.2.13
connecting to: test
...
>

any ideas, why this error occurs?

@jjallaire
Copy link
Member

My best guess is that the mongo library isn't loading due to an LD_LIBRARY_PATH difference between the shell and your R session. Can you provide a traceback associated with the error?

@mlampros
Copy link
Author

By enabling debuging (Debug > On Error > Error Inspector ) in Rstudio I receive the following output,

#-------------------------------------------------PYMONGO_reticulate.R
PyMng = reticulate::import("pymongo")
init_pym = PyMng$MongoClient(host = 'localhost', 27017L)   # I added a break point here
#-------------------------------------------------
> debugSource('~/PYMONGO_reticulate.R')
Called from: eval(expr, p)
Browse[1]> n
debug at ~/PYMONGO_reticulate.R#6: init_pym = PyMng$MongoClient(host = "localhost", 27017L)
Browse[2]> n
Error in evalq({ : attempt to apply non-function
> 

The LD_LIBRARY_PATH using the ubuntu console is

$ echo $LD_LIBRARY_PATH
/usr/local/cuda-8.0/lib64:

and from an R session,

> Sys.getenv("LD_LIBRARY_PATH")
[1] "/usr/lib/R/lib::/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/default-java/jre/lib/amd64/server"

I even modified the .profile file exporting the paths that appear in the R session, however the error persists.

Thanks for the response.

@jjallaire
Copy link
Member

I just tried to reproduce the error locally and couldn't (I can call the PyMng$MongoClient constructor with no errors).

What about if you set options(error = traceback). Does that give us a stack trace that might provide more clues?

@mlampros
Copy link
Author

I switched to another Linux OS with the same configuration. The first time I ran

options(error = traceback)
PyMng = reticulate::import("pymongo")
init_pym = PyMng$MongoClient(host = "localhost", 27017L)

I got the following traceback,

Error: attempt to apply non-function
9: stop(e)
8: value[[3L]](cond)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
6: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(loadNamespace(name), error = function(e) stop(e))
4: getNamespace(ns)
3: asNamespace(ns)
2: getExportedValue(pkg, name)
1: reticulate::import

However, since then when I attempt to run the same code I get,

Error: attempt to apply non-function
No traceback available 

a message that I received in my first Linux OS, as well.

Thanks for the response.

@jjallaire
Copy link
Member

Okay, I have now reproduce the error when using the CRAN version of reticulate (0.9). The good news is that I can't reproduce using the development version so it must be fixed there! You can install the development version with:

devtools::install_github("rstudio/reticulate")

@mlampros
Copy link
Author

yes, using the development version I don't get the error,

PyMng = reticulate::import("pymongo")

init_pym = PyMng$MongoClient('localhost', 27017L)

init_pym
MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True)

thanks a lot for all the responses and for the useful reticulate package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants