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

SystemPlatformNotSupported when running test_tutorials.py using pythonnet #333

Open
SB6988 opened this issue Mar 25, 2021 · 14 comments
Open

Comments

@SB6988
Copy link

SB6988 commented Mar 25, 2021

Hi everybody, I am trying to use Infer.NET in Python by copying your example file test_tutorials.py, which leverages pythonnet. However, I get the following error:

SystemPlatformNotSupportedException: Operation is not supported on this platform

After a list of functions that throw this error, I get:

The above exception was the direct cause of the following exception:

SystemPlatformNotSupportedError: Current platform is not supported by the current compiler choice Auto. Try a different one.

Does anybody now what is the root cause of this platform error? How do I change a compiler choice? Or is there a known workaround for this? My Python implementation is Cpython, might this be due to the fact that this is designed for IronPython only?

I am posting this here, because the code is in your repository but it does not run althought it would be expected to do so, therefore it could be an issue related to it.

@SB6988 SB6988 changed the title SystemPlatformNotSupported with SystemPlatformNotSupported when using pythonnet Mar 25, 2021
@SB6988 SB6988 changed the title SystemPlatformNotSupported when using pythonnet SystemPlatformNotSupported when running test_tutorials.py using pythonnet Mar 25, 2021
@tminka
Copy link
Contributor

tminka commented Mar 25, 2021

See issue #297

@SB6988
Copy link
Author

SB6988 commented Mar 25, 2021

Hi Tminka,

thank you for your answer. I don't think issue #297 is the same as this. The error message looks different, and here I am not using Mono, I am using instead a conda version which I used to install pythonnet via the command conda install pythonnet.

Also, if I add the line engine.Compiler.CompilerChoice = CompilerChoice.CodeDom to the code of test_tutorials.py, I get a NameError exception (name "CompilerChoice" is not defined"). In any case, in that issue the user said the installation of pythonnet via conda solved the problem for him.

To be sure we are on the same page, I think here what we have is something much more fundamental, in practice I am just trying to run your own Python example on a conda environment which has pythonnet installed.

Also, if this helps, I have run the Python example on Windows. The tutorials in C# run perfectly.

@tminka
Copy link
Contributor

tminka commented Mar 25, 2021

Pythonnet requires you to import user-defined types before you can use them. This includes CompilerChoice. It is in namespace Microsoft.ML.Probabilistic.Compiler.

@SB6988
Copy link
Author

SB6988 commented Mar 26, 2021

Ok fair point, thanks. However, this doesn't fix the issue unfortunately; if I make that addition to the code and set CompilerChoice to CodeDom, I get the same error with the new choice as the "unsupported one" on the platform:

System.PlatformNotSupportedException: Current platform is not supported by the current compiler choice CodeDom. Try a different one.

@tminka
Copy link
Contributor

tminka commented Mar 26, 2021

Okay, try CompilerChoice.Roslyn.

@SB6988
Copy link
Author

SB6988 commented Mar 26, 2021

Okay, Roslyn is apparently an available choice of the compiler, nonetheless seems that some component is still missing: now I get

System.IO.FileNotFoundException: Could not load file or assemply System.Collections.Immutable , Version=1.2.3.0, PublicKeyToken=... or one of its dependencies. The system cannot find the file specified.

@tminka
Copy link
Contributor

tminka commented Mar 28, 2021

test_tutorials.py has the line:

sys.path.append(os.path.join(os.path.dirname(__file__), r'../Tests/bin/DebugFull/net461/'))

In that folder, you should find System.Collections.Immutable.dll and all other required libraries. If you see it there and it still doesn't work, try deleting that bin folder and regenerate by re-compiling Infer.NET.

@SB6988
Copy link
Author

SB6988 commented Mar 29, 2021

Hi,

ok I think I am finding something interesting. The folder you mentioned is NOT generated at compilation -- instead of DebugFull, it generates Debug\netappcore3.1. I had already substituted the path to it.

The thing is, in that folder there are just .dll s related to GraphicalModellingLib, .cs and .csproj files -- like .NETCoreapp,VErsion3.1,AssemplyAttributes.cs and other stuff but NOT the System.Collections dlls that you mentioned.

To be more speficic, I am using Visual Studio 2019, .NETCore 3.1, and I installed Infer.NET via the Nuget manager in VS.
The solution contains two projects, one with a .NET compiler and your examples in c# (which runs succesfully) and the other one with a python interpreter (containing test_tutorial.py).

Could you please specify on how you run test_tutorials.py? This might be also related to the way VS builds the solutions -- similar errors happened in dotnet/msbuild#1582 and NuGet/Home#4488 albeit with different packages and no different languages mentioned.

@tminka
Copy link
Contributor

tminka commented Mar 29, 2021

You must build with the DebugFull configuration to generate the DebugFull folder. It will not work otherwise. I will add this note to test_tutorials.py.

@SB6988
Copy link
Author

SB6988 commented Mar 30, 2021

Hi,

thanks, that would help, along with the Compiler choice. However, I still cannot reproduce what you illustrated.

Briefly, with the Debug in Full configuration it does not create the folder DebugFull still. Inside the Debug folder instead, it does create the folders Net461 and NetStandard1.4, which are both empty.

In the folder netappcore3.1, instead, a new folder is generated, "roslyn", which contains all the systems .dll included the System.Collections.Immutable that you mentioned.

Notwithstanding, even if I append this other folder to the path, it still throws the same exception. By reading the error message, I suspect it's because what it looks for is a file or assembly that is really called "System.Collections.Immutable,version= Version=1.2.3.0,Culture=neutral,PublicKeyToken=...." and not just "System.Collections.Immutable".

@tminka
Copy link
Contributor

tminka commented Mar 30, 2021

If you don't get the DebugFull folder then you haven't set the configuration to DebugFull. The configurations are defined in Infer.sln.

@tminka
Copy link
Contributor

tminka commented Mar 30, 2021

Perhaps the underlying problem is that you are not building Infer.NET from source. If you are trying to create a brand new solution out of a subset of the Infer.NET source files, then you will have to do the work of ensuring that all of the dlls are available. Python.NET does not automatically resolve nuget references. It only works with dlls.

@SB6988
Copy link
Author

SB6988 commented Mar 30, 2021

It also occurred to me. Could be. Thanks for the suggestion, in the next days I'll try and I'll keep you posted.

@SB6988
Copy link
Author

SB6988 commented Apr 7, 2021

Hi Tom,

I have tried cloning the full repository. The solution is built successfully and the Tutorials run all succesfully - via uncommenting all the tests in RunMe.cs.

Nonetheless, although I have run Test and TestApp in DebugFull configuration, the folder "DebugFull" is not produced.
However, if I change the path to "../Tests/bin/Debug/net461/" the Python test_tutorial.py runs successfully and I succeed in replicating all of your examples -- please see attached the evidence NET.

To conclude, there were two overlapping issues:

  1. Although the solution is built in DebugFull configuration, that folder is not produced. This is not intrinsically a problem, as the path to the Debug folder works as well
  2. As you suspected, the numerous errors in cascade concerning missing dlls when trying to run the Python examples occurred
    since one needs to clone the full solution and build it in order to have all the necessary dlls. The Python example is not gonna work if one downloads the several Infer.NET Nugets (ML.Probabilistic etc.) straight from the "manage Nuget packages" option in Visual Studio.

Please do let me know in case you are interested in more details. Perhaps I would suggest to add the two aspects above in the instructions, as they would make more transparent how to replicate those examples -- especially the second one.

It might be very useful (and should be relatively quick) to identify the minimum set of dlls that PythonNet needs to run Infer.NET without needing to cloning the repository and build the full solution from there. This would be very important because some places do not allow to clone repositories due to firewall policies, whilst the Nugets are made available for installation.

Thank you very much for your time and assistance!

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

2 participants