Running Tensor flow from R using rPython - python

I'm trying to use the Tensor flow Python module in RStudio using the package rPython. I am able to use the tensor flow module directly from Python.
I have a Python file called "run.py" which imports tensor flow, and I can successfully call it in the command line using "python run.py". However, when I use the rPython package and run the following
> python.load("python/run.py")
Error in python.exec(code, get.exception) : No module named tensorflow
Using the following code produces the same error
python.exec("
import sys
sys.argv = ['']
import tensorflow as tf
")
Error in python.exec("\n import sys\n sys.argv = ['']\n import tensorflow as tf\n ") :
No module named tensorflow
Does anyone know why I get this error?

Related

Using Pytorch in AWS lambda Error- "Unable to import module 'lambda_function': No module named 'torch._C'",

I am trying to use pytorch in AWS lambda but I keep getting this error.
I am using arn:aws:lambda:us-east-1:934676248949:layer:pytorchv1-py36:2 as the layer for pytorch
and this is my handler function
import unzip_requirements
import torch
def lambda_handler(event, context):
return "Hello"
As in the function I am just only importing torch and it is giving me this error.
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'torch._C'",
"errorType": "Runtime.ImportModuleError"
}
Make sure your AWS Lambda runtime and your container (when using a layer) or your EC2 instance (when installing on EFS from EC2) use the same Python version.
PyTorch C extensions are compiled for a specific Python version and discrepancies will result in the error you got.
try:
import unzip_requirements
except ImportError:
pass
try this it passes through the ._C dependency

Can't import matlab.engine in Matlab

I installed the matlab module for python using this tutorial. Now I'm trying to import matlab.engine module in a .py file that's going to be executed inside Matlab. Here is the process and files:
My test.py file:
# test.py
import matlab.engine
On Matlab, I do:
>> mod = py.importlib.import_module('test');
>> py.reload(mod)
Error msg:
Error using test><module> (line 1)
Python Error: ImportError: No module named engine
In my python file, even inside Matlab, when I just import matlab module, it works, but when I try to import engine, it fails...
How can I import matlab.engine module inside Matlab?
Obs.:
Module matlab imported inside Matlab:
>> py.importlib.import_module('matlab')
ans =
Python module with properties:
Buffer: [1×1 py.type]
<module 'libmwbuffer' from 'C:\MATLAB\R2018b\bin\win64\libmwbuffer.pyd'>
Module matlab imported outside Matlab (cmd.exe, for instance):
>>> import matlab
>>> matlab
<module 'matlab' from 'C:\Python27\lib\site-packages\matlab\__init__.pyc'>
Look at the paths. Is it a conflict?
The import matlab.engine works outside Matlab, if I run in the cmd.exe, for example, it works.
Using Matlab 2018b, Python 2.7. Everything x64. Windows 7.

How to import "psutil"

I am trying to import and use psutil from within a python-script (.py file).
This .py file is part of a juju-charm layer. To be specific, it is a command script for collecting metrics from the machine running the charm-application:
#!/usr/bin/env python3
import psutil
if __name__ == '__main__':
cpu_times = psutil.cpu_times(percpu=False)
print(cpu_times )
Now when I build the charm-layer and deploy it using juju, I get the following error:
ImportError: No module named psutil
This means that the machine (which was brought up by juju) called and invoked that .py file successfully. But failed to import psutil.
My question is how to import psutil successfully?
(I will highly appreciate a juju-charm related answer if there is any but it is not necessary)

"import ... as .." trigger AttributeError

when I use "import as" like
import tensorflow.python.ops.control_flow_ops as ass
I get "AttributeError: module 'tensorflow' has no attribute 'python'"
but code below like
import tensorflow.python.ops.control_flow_ops
works fine
env: python 3.6.3 + tensorflow 1.3.0
This is an unfortunate combination of TensorFlow's interface sealing (e.g. removing tf.python symbol visibility from import tensorflow as tf) and Python import semantics. The import tensorflow... as syntax will only access public TensorFlow symbols, while from tensorflow... import ... as can also access private symbols with no API stability guarantees.

ImportError: No module named examples.tutorials.mnist

I am very frustrated by this error, what I did is getting the code from tensor flow tutorial to import moist:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
However when I run the python shows:
File "/Users/kevinling/Desktop/Machine Learning/tensorflow.py", line 2, in
from tensorflow.examples.tutorials.mnist import input_data
ImportError: No module named examples.tutorials.mnist
When I check into the directory, the file is perfectly there:
And the directory is:
enter image description here
The input_data.py is like:
The input_data.py
Just rename your example from "tensorflow.py" to anything else and it will work. The interpreter is trying to import the necessary files from your script.
Did you already install tensorflow? If not, follow their install instructions or simply install using pip:
pip install tensorflow
Now, make sure you are NOT currently in a folder where tensorflow is located, and try running your script.
python your_script.py

Categories