You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Py.Import returns null when importing tensorflow #299
On Fri, Dec 2, 2016, 7:48 AM Pavel Konovalov ***@***.***> wrote:
Py.Import returns null when importing tensorflow at the same time python
from command line or from IDE works with that import without any problems.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#299>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5c8ZMRupCCRSrCwlk3A5zIw_h51jks5rECGkgaJpZM4LCkWP>
.
It could help debugging to do a throw new PythonException() immediately after the Py.Import. In fact, I think this should be done in any case, instead of returning null here.
That is anaconda with python 3.5 + tensorflow. I can give you remote access with team viewer to that env with installed VS and pythonnet sources. I can debug and see that in pythonnet hook routine looks like Py.Import return some error. But it structure is very unclear for new guy in this topic, like me.
Using importlib I found the exception thrown in tensorflow.python.platform.flags
using System;
using Python.Runtime;
namespace tensorflowinclr
{
class Program
{
static void Main(string[] args)
{
dynamic tf;
dynamic gpb;
dynamic np;
using (Py.GIL()) {
np = Py.Import("numpy");
gpb = Py.Import("google.protobuf");
tf = Py.Import("tensorflow");
//tf = Py.Import("tensorflow.python.platform.flags");
tf = Py.Import("importlib");
tf = tf.import_module("tensorflow");
if (tf == null) {
Console.WriteLine("bad import");
}
}
}
}
}
Unhandled Exception: Python.Runtime.PythonException: AttributeError : module 'sys' has no attribute 'argv'
at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw) in C:\Users\denfromufa\Documents\pythonnet\src\runtime\pyobject.cs:line 688
at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw) in C:\Users\denfromufa\Documents\pythonnet\src\runtime\pyobject.cs:line 756
at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) in C:\Users\denfromufa\Documents\pythonnet\src\runtime\pyobject.cs:line 1002
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at tensorflowinclr.Program.Main(String[] args) in c:\users\denfromufa\documents\visual studio 2015\Projects\tensorflowinclr\tensorflowinclr\Program.cs:line 24
Press any key to continue . . .
I think the problem is that in pythonnet we are not setting sys.argv, like suggested in this question.
idk about another release, though I'm getting the hang of them and should be less painful now that the long description gets written from the readme.md.
Activity
den-run-ai commentedon Dec 2, 2016
filmor commentedon Dec 3, 2016
It could help debugging to do a
throw new PythonException()immediately after thePy.Import. In fact, I think this should be done in any case, instead of returningnullhere.snarb commentedon Dec 4, 2016
That is anaconda with python 3.5 + tensorflow. I can give you remote access with team viewer to that env with installed VS and pythonnet sources. I can debug and see that in pythonnet hook routine looks like Py.Import return some error. But it structure is very unclear for new guy in this topic, like me.
den-run-ai commentedon Dec 5, 2016
Using importlib I found the exception thrown in
tensorflow.python.platform.flagsI think the problem is that in pythonnet we are not setting
sys.argv, like suggested in this question.http://stackoverflow.com/questions/12230210/attributeerror-module-object-has-no-attribute-argv-when-using-python-h
@filmor what do you think?
den-run-ai commentedon Dec 5, 2016
@pkonovalov-softheme I'm able to import tensorflow in pythonnet with this temp fix.
make a file
setsysargv.pyand save it in site-packages folder:import it before tensorflow:
filmor commentedon Dec 5, 2016
Maybe we could expose a
SetArgvfunction onPy?den-run-ai commentedon Dec 5, 2016
@filmor it is already is, but it is not used in initialize:
pythonnet/src/runtime/runtime.cs
Line 2119 in e4b91d7
Update runtime.cs
den-run-ai commentedon Dec 6, 2016
I put together a pull request to resolve this issue:
#301
snarb commentedon Dec 27, 2016
Can be closed. Works. Thank you!
den-run-ai commentedon Feb 1, 2017
vmuriart commentedon Feb 1, 2017
idk about another release, though I'm getting the hang of them and should be less painful now that the long description gets written from the
readme.md.den-run-ai commentedon Jul 1, 2017
here is example how to call into tensorflow from C# using pythonnet: #473