Repository navigation
Description
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!
Activity
den-run-ai commentedon Aug 9, 2017
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 commentedon Aug 9, 2017
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 commentedon 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.
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:
I also confirmed in my settings that my system language is already US-EN. Any thoughts?
den-run-ai commentedon 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 commentedon Aug 9, 2017
@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 commentedon 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 commentedon Aug 9, 2017
@shahwill thanks for using pythonnet, closing since issue is resolved!
den-run-ai commentedon Aug 9, 2017
@shahwill don't forget to star the repo on github 🥇