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

Matlab called python Theano Module Wrong #9

Open
VeritasYin opened this issue Jan 30, 2017 · 3 comments
Open

Matlab called python Theano Module Wrong #9

VeritasYin opened this issue Jan 30, 2017 · 3 comments

Comments

@VeritasYin
Copy link

Hi! Recently, we tried to reproduce the experiment, but at the visualization part (script_viz_policy.m) has to use MATLAB call python code (vin.py). In this part, the code imports theano module (which I have already installed). But it reported an err:
Undefined variable "py" or class "py.vin.vin".

Error in script_viz_policy (line 3)
tmp = py.vin.vin; clear tmp; % to load Python

And I followed instruction of Matlab Online Help, used command py.importlib.import_module('vin') for test, and still reported an err:

Error using theano_utils> (line 3)
Python Error: ImportError: No module named theano

Error in vin> (line 3)
from theano_utils import *

Error in init>import_module (line 37)
import(name)

But I can import theano in python,

import theano
import theano.tensor as T
theano.test()
Theano version 0.8.2
theano is installed in //anaconda/lib/python2.7/site-packages/theano
NumPy version 1.11.1
NumPy relaxed strides checking option: False
NumPy is installed in //anaconda/lib/python2.7/site-packages/numpy
Python version 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)]
nose version 1.3.7

I couldn't figure out where is the problem. Thank you in advance!

@avivt
Copy link
Owner

avivt commented Jan 30, 2017 via email

@VeritasYin
Copy link
Author

VeritasYin commented Jan 31, 2017

Hi, Aviv!

It still doesn't work on Matlab R2016b.

I followed the instruction of Matlab documents, added the path into python.

P = py.sys.path;
P

P =

Python list with no properties.

['/Users/veritas/Desktop/vin', '/anaconda/lib/python2.7/site-packages/theano', '', '/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-darwin', '/usr/lib/python2.7/plat-mac', '/usr/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

I can import my own python file like mymod.py and module like numpy with no problems,

py.importlib.import_module('mymod')

ans =

Python module with properties:

theend: [1×1 py.function]
search: [1×1 py.function]

<module 'mymod' from 'mymod.pyc'>

py.importlib.import_module('numpy')

ans =

Python module with properties:

                 loadtxt: [1×1 py.function]
              reciprocal: [1×1 py.numpy.ufunc]

......

But if I want to import theano or vin.py, it reported errors:

py.importlib.import_module('theano')
Error using init>import_module (line 37)
Python Error: ImportError: No module named theano

py.importlib.import_module('vin')
Error using theano_utils> (line 3)
Python Error: ImportError: No module named theano

Error in vin> (line 3)
from theano_utils import *

Error in init>import_module (line 37)
import(name)

And also, the path for theano is a dictionary, maybe this method only works for a file (Matlab tries to find a file named theano.py?) rather a dictionary. But still, numpy is also a dic, so I am confused.

Many thanks,
veritas

@xiong-j
Copy link

xiong-j commented Sep 6, 2017

I am having a similar problem. is your problem solved?

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

3 participants