Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Setup.py fails with /langversion error #521

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

Closed
shahwill opened this issue Aug 9, 2017 · 8 comments
Closed

Setup.py fails with /langversion error #521

shahwill opened this issue Aug 9, 2017 · 8 comments

Comments

@shahwill
Copy link

shahwill commented Aug 9, 2017

Environment

  • Pythonnet version: 2.3
  • Python version: 3.5.0
  • Operating System: Windows 10

Details

  • I'm trying to install pythonnet on my local machine that has the following packages installed: Python 3.5, pip 9.0.1, setuptools 36.2.7, jsonschema 2.6.0, pytest 3.2.0, and wheel 0.29.0.
  • I've tried installing via Nuget, Pip, and from the source code, all with no luck

Nuget installation attempt

  • I created a C# Console Executable Project in Visual Studio 2017 and added the 2.3.0 version of pythonnet to the project via Nuget.

  • I fixed the badimageformatting error by switching CPU configuration to x86

  • I changed the reference for Python.Runtime.DLL to point to /PythonLocation/Lib/site-packages/Python.Runtime.DLL (which I lifted from /VS17App/packages/pythonnet_py35_dotnet2.3.0/lib/net40/Python.Runtime.DLL after the package was installed)

  • When I run the console executable in VS with a simple line of code using (Py.GIL()) {}, I obtain the following error in VS:

Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Python.Runtime!Python.Runtime.Runtime::PyImport_ImportModule' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

This is the same error referenced in #485 but referencing that runtime DLL does nothing.

Source code installation attempt

I also tried installing from source by cloning the 2.3.0 source into code /PythonLocation/Lib/site-packages/ and running the following command in powershell: python.exe .\setup.py bdist_wheel

This results in the following error stack trace:

running bdist_wheel
running build
running build_ext
Checking for updates from https://www.nuget.org/api/v2/.
Currently running NuGet.exe 4.1.0.
NuGet.exe is up to date.
MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
All packages listed in packages.config are already installed.
Microsoft (R) Manifest Tool version 6.1.7716.0
Copyright (c) Microsoft Corporation 2009.
All rights reserved.
Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\Python35\Lib\site-packages\pythonnet\src\runtime\Python.Runtime.csproj]
CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\Python35\Lib\site-packages\pythonnet\src\clrmodule\clrmodule.csproj]
Traceback (most recent call last):
  File ".\setup.py", line 408, in <module>
    zip_safe=False,
  File "C:\Python35\Lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Python35\Lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\lib\site-packages\wheel\bdist_wheel.py", line 179, in run
    self.run_command('build')
  File "C:\Python35\Lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\Lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Python35\Lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 338, in run
    self.build_extensions()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 447, in build_extensions
    self._build_extensions_serial()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 472, in _build_extensions_serial
    self.build_extension(ext)
  File ".\setup.py", line 225, in build_extension
    subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
  File "C:\Python35\Lib\subprocess.py", line 584, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" pythonnet.sln /p:Configuration=ReleaseWin /p:Platform=x86 /p:DefineConstants="PYTHON35%3BPYTHON3%3BUCS2" /p:PythonBuildDir="C:\Python35\Lib\site-packages\pythonnet\build\l
ib.win32-3.5" /p:PythonInteropFile="interop35.cs" /verbosity:minimal /p:PythonManifest="C:\Python35\Lib\site-packages\pythonnet\build\lib.win32-3.5\app.manifest" /t:Build' returned non-zero exit status 1
PS C:\Python35\Lib\site-packages\pythonnet>

Pip installation attempt

I've also tried installing via pip (pip install git+https://github.com/pythonnet/pythonnet -U --force) but that gives the same error as the one mentioned above for the source code.

Summary

I've been stuck on this for days and can't seem to be able to install pythonnet in any way. It seems like it's a C# compiler issue based on my research but I can't seem to figure it out. Any help would be appreciated! Thanks!

@den-run-ai
Copy link
Contributor

For now go to appveyor builds, select your specific Python version and architecture, then download the wheel for your version from artifacts tab:

https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master

@den-run-ai
Copy link
Contributor

Another way is to switch your system locale/language to US-EN and try again. There was a similar issue due to unmanaged exports dependency.

@shahwill
Copy link
Author

shahwill commented Aug 9, 2017

@denfromufa I installed the wheel and tarball from https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master/job/5ba22b2mit2p2y3r/artifacts after running the following commands and identifying my Python version and architecture:

PS C:\Python35\Lib\site-packages> python -V
Python 3.5.0
PS C:\Python35\Lib\site-packages> python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import platform
platform.architecture()

('32bit', 'WindowsPE')

After uninstalling the existing pythonnet files, I did the following:

PS C:\projects\pythonnet> pip install .\pythonnet-2.4.0.dev0-cp35-cp35m-win32.whl
Processing c:\projects\pythonnet\pythonnet-2.4.0.dev0-cp35-cp35m-win32.whl
Installing collected packages: pythonnet
Successfully installed pythonnet-2.4.0.dev0

PS C:\projects> tar -xvf .\pythonnet-2.4.0.dev0.tar.gz

PS C:\Python35\Lib\site-packages> cd .\pythonnet-2.4.0.dev0
PS C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0> python.exe setup.py bdist_wheel

However, I still get this error:

running bdist_wheel
running build
running build_ext
Checking for updates from https://www.nuget.org/api/v2/.
Currently running NuGet.exe 4.1.0.
NuGet.exe is up to date.
MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017
\Enterprise\MSBuild\15.0\bin'.
Restoring NuGet package NUnit.3.6.0.
Restoring NuGet package NUnit.ConsoleRunner.3.6.0.
Restoring NuGet package UnmanagedExports.1.2.7.
Adding package 'NUnit.3.6.0' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'
Adding package 'UnmanagedExports.1.2.7' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'
Adding package 'NUnit.ConsoleRunner.3.6.0' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'
Added package 'UnmanagedExports.1.2.7' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'
Added package 'NUnit.ConsoleRunner.3.6.0' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'
Added package 'NUnit.3.6.0' to folder 'C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\packages'

NuGet Config files used:
    C:\Users\wshah\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    C:\Users\wshah\.nuget\packages\
    https://api.nuget.org/v3/index.json
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Installed:
    3 package(s) to packages.config projects
Microsoft (R) Manifest Tool version 6.1.7716.0
Copyright (c) Microsoft Corporation 2009.
All rights reserved.
Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\Python35\Lib\site
-packages\pythonnet-2.4.0.dev0\src\runtime\Python.Runtime.csproj]
CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\Python35\Lib\site
-packages\pythonnet-2.4.0.dev0\src\clrmodule\clrmodule.csproj]
Traceback (most recent call last):
  File "setup.py", line 408, in <module>
    zip_safe=False,
  File "C:\Python35\Lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Python35\Lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\lib\site-packages\wheel\bdist_wheel.py", line 179, in run
    self.run_command('build')
  File "C:\Python35\Lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\Lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Python35\Lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python35\Lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 338, in run
    self.build_extensions()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 447, in build_extensions
    self._build_extensions_serial()
  File "C:\Python35\Lib\distutils\command\build_ext.py", line 472, in _build_extensions_serial
    self.build_extension(ext)
  File "setup.py", line 225, in build_extension
    subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
  File "C:\Python35\Lib\subprocess.py", line 584, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" pythonnet.sln /p:Con
figuration=ReleaseWin /p:Platform=x86 /p:DefineConstants="PYTHON35%3BPYTHON3%3BUCS2" /p:PythonBuildDir="C:\Python35\Lib\
site-packages\pythonnet-2.4.0.dev0\build\lib.win32-3.5" /p:PythonInteropFile="interop35.cs" /verbosity:minimal /p:Python
Manifest="C:\Python35\Lib\site-packages\pythonnet-2.4.0.dev0\build\lib.win32-3.5\app.manifest" /t:Build' returned non-ze
ro exit status 1

I also confirmed in my settings that my system language is already US-EN. Any thoughts?

@den-run-ai
Copy link
Contributor

den-run-ai commented Aug 9, 2017

@shahwill why are you installing both wheel and tarball? Just install the wheel. In fact I did not even mention tarball, because it is almost the same as the source code!

@den-run-ai
Copy link
Contributor

@shahwill regarding your langversion issue when compiling from source (if you still plan to build from source), the Microsoft.CodeDom.Providers.DotNetCompilerPlatform DLL may need to be updated from nuget:

https://stackoverflow.com/questions/31868803/error-invalid-option-6-for-langversion-must-be-iso-1-iso-2-3-4-5-or-defa

@shahwill
Copy link
Author

shahwill commented Aug 9, 2017

@denfromufa you're completely right, I didn't see the Python.Runtime.DLL after installing from wheel and thought I had to install the tarball as well. After adding a reference to the Runtime DLL generated by the wheel from the appveyor build, my Visual Studio project ran without any exceptions. Thanks for the help!

@den-run-ai
Copy link
Contributor

@shahwill thanks for using pythonnet, closing since issue is resolved!

@den-run-ai
Copy link
Contributor

@shahwill don't forget to star the repo on github 🥇

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