8000 Python.Net (master branch) and Visual Studio 2015 on Windows 10 · Issue #259 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Python.Net (master branch) and Visual Studio 2015 on Windows 10 #259

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
gatapia opened this issue Sep 5, 2016 · 12 comments
Closed

Python.Net (master branch) and Visual Studio 2015 on Windows 10 #259

gatapia opened this issue Sep 5, 2016 · 12 comments

Comments

@gatapia
Copy link
gatapia commented Sep 5, 2016

I'm having a bit of a hard time with a new box I've built. I have the following env:

  • Win 10
  • VS 2015 + Resharper 10
  • Anaconda 3 with an additional 2.7 environment installed using conda create -n python2 python=2.7 anaconda
  • master branch of python.net

I am trying to get the PyObjectTest running. 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:

string path = @"C:\Anaconda3\envs\python2\;" + Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Process);

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 Console project and it also fails silently on the PythonEngine.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.

@den-run-ai
Copy link
Contributor
den-run-ai commented Sep 6, 2016

@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.

@gatapia
Copy link
Author
gatapia commented Sep 6, 2016

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.

@den-run-ai
Copy link
Contributor

what is the version of Anaconda 3? I assume this is Python 3.5? Did you change the compilation symbol from PYTHON27 to PYTHON35?

@gatapia
Copy link
Author
gatapia commented Sep 6, 2016

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.

@den-run-ai
Copy link
Contributor

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:

#156 (comment)

@den-run-ai
Copy link
Contributor

@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>

@gatapia
Copy link
Author
gatapia commented Sep 7, 2016

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.

@den-run-ai
Copy link
Contributor

@gatapia all that activate.bat does is append %path% with python path in front.

@gatapia
Copy link
Author
gatapia commented Sep 7, 2016

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);

...

@gatapia gatapia closed this as completed Sep 7, 2016
@den-run-ai
Copy link
Contributor

Note that there is an open issue about setting pythonpath and pythonhome from pythonnet:

#179

@AK47dev1
Copy link
AK47dev1 commented Aug 25, 2019

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.

Screen Shot 2019-08-25 at 17 33 40

@AK47dev1
Copy link
AK47dev1 commented Aug 25, 2019

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.

Screen Shot 2019-08-25 at 17 33 40

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

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

3 participants
0