0

When I was trying to import modules like "pymc3" or "theano", the rPython or PythoninR are not able to locate these modules even though I have already installed them. I am using Ubuntu 16.04, R 3.4.2, and python 3.5.2

It seems like these two packages fail to locate a certain folder, but it doesn't work after I append the path into sys.path, which contains all the packages I need, by using this command:

pyExec("sys.path.append('/home/lijiakai/.local/lib/python3.5/site-packages')")

Result also seems like good:

pyExec('import sys; print(sys.path)')

['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages', '.', '/home/lijiakai/.local/lib/python3.5/site-packages']

I imported the packages:

pyExec('import pymc3')

Then received the following errors:

Traceback (most recent call last):   File "<string>", line 1, in
<module> **ImportError** :  No module named 'pymc3' Error in
pyExec("import pymc3") :    An error has occured while executing
Python code. See traceback above.

Totally got me crazy ... really appreciate if anyone can help me out here. Thanks

4
  • what does system("which python") return? Commented Nov 21, 2017 at 7:26
  • it is /usr/bin/python, but when I run python in bash, the version is 3.5.2, which should be right Commented Nov 23, 2017 at 3:10
  • and what does: library(rPython) python.exec(c("import sys", "\n", "print(sys.version)")) return? I suspect that rPython is using another Python version, not 3.5.2 Commented Nov 23, 2017 at 8:44
  • Yes, this is true, I got python 2.7.10 in R when using the library(rPython) T_T Commented Nov 25, 2017 at 7:39

1 Answer 1

1

If you use anaconda, you might want to turn to turn to the package reticulate, where you can specify the python version to use.

# install.packages("reticulate")
library(reticulate)
use_python("/anaconda/bin/python")

However, from my experience this is slower.

Otherwise, if you use 'standard' Python, you can start by removing rPython:

remove.packages("rPython")

And then re-install it specifying the version:

install.packages("rPython", configure.vars= "RPYTHON_PYTHON_VERSION=3.5")

This should then use Python_3.5 on your machine, see here for more details.

You can test, if it was successful by using:

library(rPython)
python.exec(c("import sys", "\n", "print(sys.version)"))
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your kind help, but I still got a python version of 2.7.10 after specified ""RPYTHON_PYTHON_VERSION=3.5" when install the package, which is so frustrating ...
Are you using anaconda?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.