Skip to content

Python 3.5 support #103

Closed
Closed

Description

@fdanny

Python 3.5 support pythonnet. It supports up to 3.4.

Activity

  1. brisingraerowing commented on Sep 20, 2015

    @brisingraerowing

    I'd like this as well.

  2. brisingraerowing commented on Sep 20, 2015

    @brisingraerowing

    I just submitted a pull request with initial Python 3.5 support.

  3. fdanny commented on Oct 1, 2015

    @fdanny
    ContributorAuthor

    Did the pull request #104 go thru? Can we close this issue?

  4. vmuriart commented on Oct 16, 2015

    @vmuriart
    Contributor

    The pull request seems to have been closed without merging.

  5. mahibra commented on Jan 18, 2016

    @mahibra

    Any news on the python 3.5 support? I would love to use Python.NET with the current Python version.

  6. den-run-ai commented on Jan 27, 2016

    @den-run-ai
    Contributor

    Very weird - that pull request points to an unknown branch

  7. den-run-ai commented on Jan 27, 2016

    @den-run-ai
    Contributor
  8. den-run-ai commented on Jan 27, 2016

    @den-run-ai
    Contributor

    Looks like this branch can be merged:

    https://github.com/sdpython/pythonnet3

  9. vmuriart commented on Jan 28, 2016

    @vmuriart
    Contributor

    From reading the blog it seems that it still has a few issues to resolve

    On Wednesday, January 27, 2016, denfromufa [email protected] wrote:

    Looks like this branch can be merged:

    https://github.com/sdpython/pythonnet3

    —
    Reply to this email directly or view it on GitHub
    #103 (comment)
    .

  10. vmuriart commented on Feb 4, 2016

    @vmuriart
    Contributor

    @denfromufa I'd like to withdraw my earlier statement, I reread the blog and looks like I misunderstood the issue. He had a built issue that he mentioned.

    I took a look at the src and compared it to the earlier pr that was submitted. sdpython's looks alot more complete as it integrates the new 3.5 features.

    @tonyroberts any reason this can't be merged (other than no existing pull request 😸 )

  11. tonyroberts commented on Feb 4, 2016

    @tonyroberts
    Contributor

    @vmuriart would be great if you could test and create a PR. Please make sure you add 3.5 builds to the travis and appveyor CI builds.

  12. den-run-ai commented on Feb 16, 2016

    @den-run-ai
    Contributor

    @fdanny @mahibra @brisingraerowing try this branch until it is merged:

    https://github.com/denfromufa/pythonnet/tree/develop

    only one very weird test case is failing on travis ci, hence I commented out it for now.

    appveyor needs some updates for python 3.5, but I tested locally on my windows 7 machine.

  13. mahibra commented on Feb 17, 2016

    @mahibra

    Hi,
    I just tried to install pythonnet from your develop branch. I used Anaconda
    2.5 (Python 3.5.1) in combintation with Visual Studio Express 2015 and ran

    python setup.py install
    

    To get pythonnet running I had to manually copy all files from the
    build/lib.win-amd64-3.5 folder to the anaconda install path.
    Afterwards I was able to import clr.

    The two demo files helloform.py and splitter.py seem to run correctly.
    However, the file wordpad.py exits with the following error:

    [Anaconda35] c:\JLINK_64\software\pythonnet-develop\demo>python wordpad.py
    Traceback (most recent call last):
    File "wordpad.py", line 430, in
    main()
    File "wordpad.py", line 425, in main
    app = Wordpad()
    File "wordpad.py", line 25, in init
    self.InitializeComponent()
    File "wordpad.py", line 208, in InitializeComponent
    self.richTextBox.Font = System.Drawing.Font("Tahoma", 10)
    TypeError: no constructor matches given arguments

    Additionally I connected to the proprietary .NET API I used successfully
    with python 3.4 and pythonnet. Here I get an error when running a function
    which uses output variables. According to the C# API documentation the
    function takes the following arguments:

    bool ReadNextResult(
    out int rayNumber,
    out int errorCode,
    out int vignetteCode,
    out double X,
    out double Y,
    out double Z,
    out double L,
    out double M,
    out double N,
    out double opd,
    out double l2,
    out double m2,
    out double n2,
    out double intensity
    )

    With Python 3.4 and the pythonnet package from pypi, I was able to call
    this function in the following way:

    out = BatchRayTrace.ReadNextResult(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

    with Python 3.5 and the pythonnet version built from your develop branch I
    get the following error:

    Traceback (most recent call last):

    File "", line 1, in
    runfile('C:/JLINK_64/workspace/ZOS/PythonNet_ZOS_Raytrace.py',
    wdir='C:/JLINK_64/workspace/ZOS')

    File
    "C:\JLINK_64\software\Anaconda35\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
    line 699, in runfile
    execfile(filename, namespace)

    File
    "C:\JLINK_64\software\Anaconda35\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
    line 88, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

    File "C:/JLINK_64/workspace/ZOS/PythonNet_ZOS_Raytrace.py", line 94, in

    results = batchRayTrace.ReadNextResult(*dummyInput)

    TypeError: No method matches given arguments

    Running BatchRayTrace.ReadNextResult? in IPython gives:
    batchRayTrace.ReadNextResult?
    Type: MethodBinding
    String form: <bound method 'ReadNextResult'>
    File:
    c:\jlink_64\software\anaconda35\lib\site-packages\pythonnet-2.1.0.dev1-py3.5-win-amd64.egg\clr.pyd
    Docstring:
    Boolean ReadNextResult(Int32 ByRef, Int32 ByRef, Int32 ByRef, Int32 ByRef)
    Boolean ReadNextResult(Int32 ByRef, Int32 ByRef, Double ByRef, Double
    ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef)
    Boolean ReadNextResult(Int32 ByRef, Int32 ByRef, Int32 ByRef, Double ByRef,
    Double ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef,
    Double ByRef)
    Boolean ReadNextResult(Int32 ByRef, Int32 ByRef, Int32 ByRef, Double ByRef,
    Double ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef,
    Double ByRef, Double ByRef, Double ByRef, Double ByRef)
    Boolean ReadNextResult(Int32 ByRef, Int32 ByRef, Int32 ByRef, Double ByRef,
    Double ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef,
    Double ByRef, Double ByRef, Double ByRef, Double ByRef, Double ByRef)

    Do you have an explanation for this error and can you give me instructions
    on how it could be fixed?

    Thank you very much!

    Best regards,
    Matthias

  14. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    @mahibra can you edit your comment with code blocks according to github markdown:

    https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code

  15. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    python setup.py install is not supported, instead first you need to build a wheel and then install it e.g. usingpip.

    #123

  16. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    all 3 demos work on python 3.5, 32bit, perhaps this is specific to 64bit python or your installation. The appveyor CI is not failing on 64bit python 3.5 for the tests. the demos are not setup for testing on appveyor.

    Here is python 3.5 I tested this on locally:

    Python 3.5.1 |Continuum Analytics, Inc.| (default, Jan 29 2016, 15:46:01) [MSC v
    .1900 32 bit (Intel)] on win32
    

    once you build the wheel and install it, copy Python.Test.dll to your ..\lib\site-packages folder and then run the tests from pythonnet source folder: python src\tests\runtests.py

  17. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    i got the same error if I use wrong python version (2.7) to run wordpad.py, which suggests that you may have similar problem with activated conda environment, so try building debug version of pythonnet from VS2015 and see where pythonnet is loading from:

    [py35] C:\pythonnet\pythonnet35\demo>python helloform.py
    Attempting to load Python.Runtime using standard binding rules...
    Attempting to load Python.Runtime from: 'C:\Python\Python27\envs\py35\lib\site-p
    ackages\Python.Runtime.dll'...
    C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b7
    7a5c561934e089\System.Windows.Forms.dll
    form created
    app referenced

    and failing case due to my stupid mistake:

    [py35] C:\pythonnet\pythonnet35\demo>wordpad.py
    Attempting to load Python.Runtime using standard binding rules...
    Attempting to load Python.Runtime from: 'C:\Python\Python27\lib\site-packages\Py
    thon.Runtime.dll'...
    Traceback (most recent call last):
      File "C:\pythonnet\pythonnet35\demo\wordpad.py", line 430, in <module>
        main()
      File "C:\pythonnet\pythonnet35\demo\wordpad.py", line 425, in main
        app = Wordpad()
      File "C:\pythonnet\pythonnet35\demo\wordpad.py", line 25, in __init__
        self.InitializeComponent()
      File "C:\pythonnet\pythonnet35\demo\wordpad.py", line 208, in InitializeCompon
    ent
        self.richTextBox.Font = System.Drawing.Font("Tahoma", 10)
    TypeError: no constructor matches given arguments
    
    [py35] C:\pythonnet\pythonnet35\demo>python splitter.py
    Attempting to load Python.Runtime using standard binding rules...
    Attempting to load Python.Runtime from: 'C:\Python\Python27\envs\py35\lib\site-p
    ackages\Python.Runtime.dll'...
  18. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    regarding your overloading failure, this is most likely due to this commit, so try the develop branch before that merge:

    #151

  19. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    I could not reproduce your overloading problem with both static and instance methods:

    1. with unbound methods (static):
    C:\Python\Python27_64b>Scripts\activate.bat py35
    Activating environment "C:\Python\Python27_64b\envs\py35"...
    
    [py35] C:\Python\Python27_64b>cd env
    The system cannot find the path specified.
    
    [py35] C:\Python\Python27_64b>cd envs
    
    [py35] C:\Python\Python27_64b\envs>cd py35
    
    [py35] C:\Python\Python27_64b\envs\py35>python
    Python 3.5.1 |Continuum Analytics, Inc.| (default, Jan 29 2016, 15:01:46) [MSC v
    .1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import clr
    >>> clr.AddReference(r"C:\Users\denis.akhiyarov\Documents\visual studio 2015\Pro
    jects\ClassLibrary2\ClassLibrary2\bin\Debug\ClassLibrary2.dll")
    <System.Reflection.RuntimeAssembly object at 0x0000000002DD5390>
    >>> import ClassLibrary2
    >>> import ClassLibrary2 as cl2
    >>> dir(cl2)
    ['Class1', '__class__', '__delattr__', '__delete__', '__dir__', '__doc__', '__eq
    __', '__file__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__
    ', '__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__'
    , '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__sizeof
    __', '__str__', '__subclasshook__']
    >>> dir(cl2.Class1)
    ['Equals', 'Finalize', 'GetHashCode', 'GetType', 'MemberwiseClone', 'Overloads',
     'ReadNextResult', 'ReferenceEquals', 'ToString', '__call__', '__class__', '__de
    lattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
     '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__'
    , '__le__', '__lt__', '__module__', '__ne__', '__new__', '__overloads__', '__red
    uce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__',
     '__str__', '__subclasshook__']
    >>> cl2.Class1.Overloads
    ClassLibrary2.Class1()
    >>> cl2.Class1.ReadNextResult
    <unbound method 'ReadNextResult'>
    >>> cl2.Class1.ReadNextResult(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    ... 0.0, 0.0, 0.0, 0.0, 0.0)
    14
    1. with bound methods (instance):
    [py35] C:\Python\Python27_64b\envs\py35>python
    Python 3.5.1 |Continuum Analytics, Inc.| (default, Jan 29 2016, 15:01:46) [MSC v
    .1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    
    >>> import clr
    >>> clr.AddReference(r"C:\Users\denis.akhiyarov\Documents\visual studio 2015\Pro
    jects\ClassLibrary2\ClassLibrary1\bin\Debug\ClassLibrary1.dll")
    <System.Reflection.RuntimeAssembly object at 0x0000000002CA5390>
    >>> import ClassLibrary1 as cl1
    >>> dir(cl2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'cl2' is not defined
    >>> dir(cl1)
    ['Class1', '__class__', '__delattr__', '__delete__', '__dir__', '__doc__', '__eq
    __', '__file__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__
    ', '__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__'
    , '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__sizeof
    __', '__str__', '__subclasshook__']
    >>> dir(cl1.Class1)
    ['Equals', 'Finalize', 'GetHashCode', 'GetType', 'MemberwiseClone', 'Overloads',
     'ReadNextResult', 'ReferenceEquals', 'ToString', '__call__', '__class__', '__de
    lattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
     '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__'
    , '__le__', '__lt__', '__module__', '__ne__', '__new__', '__overloads__', '__red
    uce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__',
     '__str__', '__subclasshook__']
    >>> cl2.Class1.ReadNextResult
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'cl2' is not defined
    >>> cl1.Class1.ReadNextResult
    <unbound method 'ReadNextResult'>
    >>> cl1inst = cl1.Class1()
    >>> cl1inst.ReadNextResult
    <bound method 'ReadNextResult'>
    >>> cl1inst.ReadNextResult(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    ... 0.0, 0.0, 0.0, 0.0, 0.0)
    14

    C# code for both classes:

    using System;
    
    namespace ClassLibrary1
    {
        public class Class1
        {
            public Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Int32 ByRef4)
            {
                return 4;
            }
            public Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Double ByRef3, Double
            ByRef4, Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9)
            {
                return 9;
            }
            public Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10)
            {
                return 10;
            }
            public Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10, Double ByRef11, Double ByRef12, Double ByRef13)
            {
                return 13;
            }
            public Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10, Double ByRef11, Double ByRef12, Double ByRef13, Double ByRef14)
            {
                return 14;
            }
        }
    }
    
    using System;
    
    namespace ClassLibrary2
    {
        public class Class1
        {
            public static Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Int32 ByRef4)
            {
                return 4;
            }
            public static Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Double ByRef3, Double
            ByRef4, Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9)
            {
                return 9;
            }
            public static Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10)
            {
                return 10;
            }
            public static Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10, Double ByRef11, Double ByRef12, Double ByRef13)
            {
                return 13;
            }
            public static Int32 ReadNextResult(Int32 ByRef1, Int32 ByRef2, Int32 ByRef3, Double ByRef4,
            Double ByRef5, Double ByRef6, Double ByRef7, Double ByRef8, Double ByRef9,
            Double ByRef10, Double ByRef11, Double ByRef12, Double ByRef13, Double ByRef14)
            {
                return 14;
            }
        }
    }
    
  20. mahibra commented on Feb 18, 2016

    @mahibra

    @denfromufa Thank you very much for the instantaneous help!

    Replacing methodbinder.cs with the state before commit #151 fixed both my issues with the third party API and with the wordpad.py demo file.

    I tried to build a wheel by running
    python setup.py bdist_wheel
    which gives the following output in the last line:
    creating build\bdist.win-amd64\wheel\pythonnet-2.1.0.dev1.dist-info\WHEEL
    However, the folder build\bdist.win-amd64\ is empty.

    I also tried to use code blocks in yesterday's messge which does not work while this comment is formatted correctly.

  21. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    @mahibra I'm glad that your overloading problem is resolved, although temporarily. Can you share the complete code that can be reproduced to fix this overloading exception? As you can see above - my c# snippet does not reproduce this problem.

    wordpad.py should not be affected by my commit #151 at all. I could NOT reproduce this problem with both python 3.5 32bit & 64bit on my latest develop branch.

  22. den-run-ai commented on Feb 18, 2016

    @den-run-ai
    Contributor

    @mahibra once you build the wheel, its location is .\dist folder, not the .\build folder.

  23. mahibra commented on Feb 18, 2016

    @mahibra

    @denfromufa You are correct, I found the wheel in the .\dist folder.
    From my perspective, it does not make sense to share the code which caused the overload error. It can only be used with the commercial program ZEMAX OpticStudio. This software requires a hardware dongle and the source code of the API is not publicly available.

    Interesingly, I found a similar overloaded method in the same API which works with the newer version of methodbinder.cs.

  24. tonyroberts commented on Feb 24, 2016

    @tonyroberts
    Contributor

    This is now done. @denfromufa @vmuriart see PR 163 for details. Note that unlike the previous attempts this builds the TypeOffset class from the python headers, and so the order of the struct members is now correct (in the previous PRs there seemed to be a lot of confusion and errors in that area). For the most usual Python configurations I've checked in the auto generated code, but if you are using something else (e.g. Python built with Py_DEBUG) then setup.py will attempt to generate the correct class, which requires clang to be installed. All tests are passing without modification.

  25. vmuriart commented on Feb 24, 2016

    @vmuriart
    Contributor

    @tonyroberts sweet. Thanks for getting this closed.
    Just looked over the code, I didn't see where you are specifying which Interop to be used.

    Were you still planning on releasing 2.1 and updating the master branch?

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