Repository navigation
Python.Net (master branch) and Visual Studio 2015 on Windows 10 #259
Description
Activity
@gatapia how are you running the embedding tests? command-line or VS UI?
Is this failing on both root env (py3) and additional env (py27)?
I got this weird PythonEngine.Initialize() call crash when using Python 2.7.11, which was caused by issues in CPython. I'll try to link that issue.
VS UI (using resharper). py3 fails with DllNotFoundException py27 fails silently. I tried the Console project using command line and that also fails with message: "ImportError: No module named site". Trying to debug Console fails silently.
what is the version of Anaconda 3? I assume this is Python 3.5? Did you change the compilation symbol from PYTHON27 to PYTHON35?
Setting the compilation symbol to PYTHON35 appears to work. I was trying to load a 2.7 module tho. However, it may be simpler to upgrade my python code than workout why Win10+py27+pynet is not working.
I'll give that a go but the issue still remains; i.e. pythonnet 64 + py27 + win10 does not appear to work. I tried on a Win10 machine without 3.x (only 27) and got the same issues.
Here is the issue with python 2.7.11 (2 bugs in CPython) that I mentioned before, so try python 2.7.10 or python 2.7.12:
@gatapia ok, I reproduced this issue with conda environments, and here is a quick fix for you:
C:\Users\denfromufa\Documents\pythonnet>activate py27 (py27) C:\Users\denfromufa\Documents\pythonnet>where python C:\Python\Miniconda3_64b\envs\py27\python.exe C:\Python\Miniconda3_64b\python.exe (py27) C:\Users\denfromufa\Documents\pythonnet>set PYTHONHOME=C:\Python\Miniconda3_64b\envs\py27\ (py27) C:\Users\denfromufa\Documents\pythonnet>set PYTHONPATH=C:\Python\Miniconda3_64b\envs\py27\Lib (py27) C:\Users\denfromufa\Documents\pythonnet>npython Python 2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> exit() (py27) C:\Users\denfromufa\Documents\pythonnet>just running activate py27 works for me, infact setting PYTHONHOME/PATH breaks it.
Now I just need to find how to simulate the activate command in a .Net environment.
Thanks for your help @denfromufa much appreciated.
@gatapia all that activate.bat does is append %path% with python path in front.
Thanks @denfromufa all sorted, my final incode solution is:
string path = @"c:\dev\libs\Anaconda3\envs\python2;" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine); Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONHOME", @"c:\dev\libs\Anaconda3\envs\python2", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONPATH ", @"c:\dev\libs\Anaconda3\envs\python2\Lib", EnvironmentVariableTarget.Process); ...Reacted by Aditya SharmaReacted by Aditya SharmaNote that there is an open issue about setting pythonpath and pythonhome from pythonnet:
Thanks @denfromufa all sorted, my final incode solution is:
string path = @"c:\dev\libs\Anaconda3\envs\python2;" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine); Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONHOME", @"c:\dev\libs\Anaconda3\envs\python2", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONPATH ", @"c:\dev\libs\Anaconda3\envs\python2\Lib", EnvironmentVariableTarget.Process); ...---EDIT---
I missed the point in the next comment. Now works for me.
---EDIT---Doing the same but not working!
First added Python.Runtime.dll as a reference,
Second wrote using Python.Runtime at the top;
Finally the exact code above(I'm not using the virtual environment in this specific case).Entire code is not included though to lack of space.
Thanks @denfromufa all sorted, my final incode solution is:
string path = @"c:\dev\libs\Anaconda3\envs\python2;" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine); Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONHOME", @"c:\dev\libs\Anaconda3\envs\python2", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PYTHONPATH ", @"c:\dev\libs\Anaconda3\envs\python2\Lib", EnvironmentVariableTarget.Process); ...Doing the same but not working!
First added Python.Runtime.dll as a reference,
Second wrote using Python.Runtime at the top;
Finally the exact code above(I'm not using the virtual environment in this specific case).Entire code is not included though to lack of space.
I just made it work by setting platform target on x64 cause I'm using 64-bit system architecture.
Follow the steps above then move to Solution Explorer, open properties by double-clicking on it, move to Build tab, change Platform target to your system architecture type!Source helping me: HERE
I'm having a bit of a hard time with a new box I've built. I have the following env:
conda create -n python2 python=2.7 anacondaI am trying to get the
PyObjectTestrunning. If I run this I get:System.DllNotFoundException : Unable to load DLL 'python27': The specified module could not be found. (Exception from HRESULT: 0x8007007E)Ok looks like it may be trying to load python27 and python3.x is the default. So I add this to the test:
The Unit Test then fails with no exception with the following error: 'Aborted' (no more details). Debugging does not help.
I have looked at the FAQ and searched the google (event Bing!!) and whilst there is plenty of info out there it all looks old.
Anyone had any luck with this kind of setup, my ultimate goal is to embed python in a .Net application. I will try to put this in a console application to try to remove unit tests (and resharper) from the equation but I don't think that will help. Done: Verified using the
Consoleproject and it also fails silently on thePythonEngine.Initialize()call.Note: I have verified that I am using 64 bit python (2.7 and 3.x) and I have verified that Python.Runtime and Python.Embedding.Tests are also targeting 64 bit so I dont think bitness is the issue.