FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Py.Import returns null when importing tensorflow · Issue #299 · pythonnet/pythonnet · GitHub

Repository navigation

Py.Import returns null when importing tensorflow  #299

Closed

Description

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.

Activity

  1. den-run-ai commented on Dec 2, 2016

    Contributor
  2. filmor commented on Dec 3, 2016

    Member

    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.

  3. snarb commented on Dec 4, 2016

    Author

    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.

  4. den-run-ai commented on Dec 5, 2016

    Contributor

    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.

    http://stackoverflow.com/questions/12230210/attributeerror-module-object-has-no-attribute-argv-when-using-python-h

    @filmor what do you think?

  5. den-run-ai commented on Dec 5, 2016

    Contributor

    @pkonovalov-softheme I'm able to import tensorflow in pythonnet with this temp fix.

    make a file setsysargv.py and save it in site-packages folder:

    import sys
    setattr(sys,"argv",[""])
    

    import it before tensorflow:

    using System;
    using Python.Runtime;
    
    namespace tensorflowinclr
    {
        class Program
        {
            static void Main(string[] args)
            {
                dynamic tf;
                dynamic gpb;
                dynamic np;
                dynamic sys;
                using (Py.GIL()) {
                    np = Py.Import("numpy");
                    gpb = Py.Import("google.protobuf");
                    sys = Py.Import("setsysargv");
                    tf = Py.Import("tensorflow");
                    if (tf == null) {
                        Console.WriteLine("bad import");
                    }
                }
            }
        }
    }
    
  6. filmor commented on Dec 5, 2016

    Member

    Maybe we could expose a SetArgv function on Py?

  7. den-run-ai commented on Dec 5, 2016

    Contributor

    @filmor it is already is, but it is not used in initialize:

    PySys_SetArgv(int argc, IntPtr argv);

  8. added a commit that references this issue on Dec 6, 2016
  9. den-run-ai commented on Dec 6, 2016

    Contributor

    I put together a pull request to resolve this issue:

    #301

  10. snarb commented on Dec 27, 2016

    Author

    Can be closed. Works. Thank you!

  11. den-run-ai commented on Feb 1, 2017

    Contributor
  12. vmuriart commented on Feb 1, 2017

    Contributor

    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.

  13. den-run-ai commented on Jul 1, 2017

    Contributor

    here is example how to call into tensorflow from C# using pythonnet: #473

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL