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

Python module tensorflow was not found - but only when run in Rstudio #87

Closed
stevetbright opened this issue Feb 13, 2017 · 9 comments
Closed

Comments

@stevetbright
Copy link

A simple 'hello world' runs just fine from the command line ( via Rscript hello.R )

library(tensorflow)
sess<-tf$Session()
hello <- tf$constant('Hello, TensorFlow!')
sess$run(hello) 

However, running from inside the Rstudio (server) IDE gives the error:

sess<-tf$Session()
Error: Python module tensorflow was not found.

In both cases py_config() returns:

Detected Python configuration:

python: /usr/bin/python
libpython: /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome: /usr:/usr
version: 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
numpy: /usr/local/lib/python2.7/dist-packages/numpy
numpy_version: 1.12.0
tensorflow: /usr/local/lib/python2.7/dist-packages/tensorflow

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

Is there some other set of path variables I could be checking and modifying?

SessionInfo() from IDE:

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] tools stats graphics grDevices utils datasets methods base

other attached packages:
[1] tensorflow_0.6.0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 reticulate_0.6.0

@jjallaire
Copy link
Member

For some reason tensorflow can't be loaded when in RStudio Server in your configuration.

Try a plain import statement on "tensorflow" to see if you get more diagnostics as to why:

tflow <- import("tensorflow")

@stevetbright
Copy link
Author

ok hanks just ran and got:

> tflow <- import("tensorflow")
Error in py_module_import(module) : 
  ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory

Detailed traceback: 
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 45, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

But I would have thought it would have been found:

> Sys.getenv("LD_LIBRARY_PATH")
[1] "/usr/lib/R/lib::/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server:/usr/local/cuda-7.0/lib64"
> system("ls -l /usr/local/cuda-7.0/lib64/libcudart.so.7.0*")
lrwxrwxrwx 1 root root     19 Jul  6  2016 /usr/local/cuda-7.0/lib64/libcudart.so.7.0 -> libcudart.so.7.0.28
-rwxr-xr-x 1 root root 377896 Jul  6  2016 /usr/local/cuda-7.0/lib64/libcudart.so.7.0.28

@jjallaire
Copy link
Member

It could be that libcudart.so.7.0 itself has dependencies that aren't being found. What happens if you try:

system("ldd /usr/local/cuda-7.0/lib64/libcudart.so.7.0")

@stevetbright
Copy link
Author

> system("ldd /usr/local/cuda-7.0/lib64/libcudart.so.7.0")
	linux-vdso.so.1 =>  (0x00007ffe91d68000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9ac3f72000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9ac3d6e000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9ac3b50000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9ac3948000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f9ac4594000)

@jjallaire
Copy link
Member

I have no idea then :-\ LD_LIBRARY_PATH issues can be very hard to run down. It could be that the library is found but for some other reason is failing to load.

For whatever reason TF can't load that library but without getting hands on your system it's hard to say why.

@stevetbright
Copy link
Author

I was able to fix this by running:

sudo ldconfig /usr/local/cuda/lib64

NVIDIA/DIGITS#8

Thanks!

@jjallaire
Copy link
Member

Great!

@mickguy
Copy link

mickguy commented Jun 22, 2017

I had the same issue but then it worked by re-starting RStudio

@koolmon
Copy link

koolmon commented Feb 28, 2018

I am relatively new to Python so wanted to share what happened to me when I had a similar problem and how I solved it.

My problem was because although I had already installed Python I hadn't realised I needed to actually install TensorFlow!

I used this link to install TensorFlow: https://www.tensorflow.org/install/
I followed the instructions and installed TensorFlow with CPU support (rather than GPU support) as the website recommended doing this first as it is easier to install.

Following this I restarted RStudio and ran:
install.packages("tensorflow")
library(tensorflow)

Then I ran a little test:

## Not run: 
library(tensorflow)
hello <- tf$constant('Hello, TensorFlow!')
zeros <- tf$Variable(tf$zeros(shape(1L)))
sess <- tf$Session()
sess$run(tf$global_variables_initializer())
sess$run(hello)
sess$run(zeros)
## End(Not run)

And it worked as hoped.

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

4 participants