- Notifications
You must be signed in to change notification settings - Fork768
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Environment
DetailsP.S. - I was able to solve this issue, however since I didn't find any answer responding to this aspect anywhere, thought it might help the community.
stringpathToVirtualEnv=/path/to/venv/;Environment.SetEnvironmentVariable("PATH",pathToVirtualEnv,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONHOME",pathToVirtualEnv,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONPATH",$"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib",EnvironmentVariableTarget.Process);PythonEngine.PythonHome=pathToVirtualEnv;PythonEngine.PythonPath=Environment.GetEnvironmentVariable("PYTHONPATH",EnvironmentVariableTarget.Process);
ImportError :Nomodulenamed'_ctypes' This change to the above code finally worked for me. Note - my initial PYTHONPATH points to python path corresponding the parent python I used to create the virtual environment (i.e. Python 3.7) PythonEngine.PythonPath=PythonEngine.PythonPath+";"+Environment.GetEnvironmentVariable("PYTHONPATH",EnvironmentVariableTarget.Process); |
BetaWas this translation helpful?Give feedback.
All reactions
👍 7❤️ 1
Replies: 10 comments 1 reply
-
you saved my day. thx |
BetaWas this translation helpful?Give feedback.
All reactions
😄 4
-
Starting with Python.NET 3.0 you will also need to set |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
thnx for the heads up! |
BetaWas this translation helpful?Give feedback.
All reactions
-
How I got it working *Python 3.8 So I am adding three parts on to the end of the existing python path
Output Then it goes on to run these successfully A bit silly, but note in your venv you obviously need to have installed numpy into your venv first. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I found, to use a Notice
Not sure why yet. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2🚀 2
-
Took me a whole day to get my VirtualEnvironment working by following the exact steps above (in |
BetaWas this translation helpful?Give feedback.
All reactions
-
Just moving the PythonEngine.Initialize(); before PythonEngine worked for me, thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
-
If anyone has some nice examples (this repo lacks them) would be great to see them./ |
BetaWas this translation helpful?Give feedback.
All reactions
-
On Windows the provided example fromhttps://github.com/pythonnet/pythonnet/wiki/Using-Python.NET-with-Virtual-Environments worked just fine (no need to call PythonEngine.Initialize(); before setting PythonHome and PythonPath). However, I can not get this working on Linux (Ubuntu 20.04). If someone has any advices, please add a comment below. Thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
@helldanno Instead of ";" and "\" on Windows, I think Linux uses ":" and "/". Maybe change code to use System.IO.Path.DirectorySeparatorChar instead of "\" backslash For environment variable delimiter find it with below. There might be a better way. |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #1348 on February 29, 2024 08:04.