Comments (13)
And this is of course still necessary in Global.asax.cs
// this call initializes numpy. it is necessary to do that before PythonEngine.BeginAllowThreads()
np.arange(1);
PythonEngine.BeginAllowThreads(); // <--- this is very important for a web server since all requests are on different threads
from numpy.net.
public class Program
{
public static void Main(string[] args)
{
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Add these two lines:
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
from numpy.net.
public class Program { public static void Main(string[] args) { PythonEngine.Initialize(); PythonEngine.BeginAllowThreads(); CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>(); }Add these two lines:
PythonEngine.Initialize(); PythonEngine.BeginAllowThreads();
@Esther2013
I can't find Program.cs. I put it into Application_Start in global but It cause other problem
Unable to load DLL 'python37': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
from numpy.net.
When you look at the Examples folder of the Numpy.NET source, there is a WebApiExample. Can you check it out please and see if that works for you? I am pretty sure it is, like Esther Hu says, that you are missing the line PythonEngine.BeginAllowThreads();
at some point.
from numpy.net.
ok, @Esther2013 was almost correct but not quite. You need to do this:
// this call initializes numpy. it is necessary to do that before PythonEngine.BeginAllowThreads()
np.arange(1);
PythonEngine.BeginAllowThreads(); // <--- this is very important for a web server since all requests are on different threads
from numpy.net.
Hi @henon! After solving the Dll not found problem in Local IIS by using
Environment.SetEnvironmentVariable("PATH", @"C:\Python37\",EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONHOME", @"C:\Python37\", EnvironmentVariableTarget.Process);
and also add Numpy.np.arange(1);
PythonEngine.BeginAllowThreads();
in Startup.cs, it cause new problem. When ever I run to this line
var rs = np.linalg.norm(np.array(arr1) - np.array(arr2));
IIS force close without any message except Exception thrown: 'System.AccessViolationException' in Python.Runtime.dll
in VS output window
I've tried pass PythonEngine.BeginAllowThreads();
after and before var rs = np.linalg.norm(np.array(arr1) - np.array(arr2));
It still close suddenly.
--update 1: I still try update code to IIS server but a weird err Access to the path 'c:\windows\system32\inetsrv\python-3.7.3-embed-amd64.zip' is denied
appear in Numpy.np.arange(1);
, then I tried to set permission but seems like setting permission is not allowed.
--update 2: After commented Numpy.np.arange(1);
, Unable to load DLL 'python37': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
appear again, OMG :((
from numpy.net.
ok, so it seems in your usecase you can't use numpy.net which automatically install python in the AppData directory per default. Can you manually install python on the machine or should it be deployed automatically? Depending on the choice there are different solutions.
if you have manually set up numpy in C:\Python37 you should reference the Numpy.Bare nuget. Which do you reference?
from numpy.net.
@henon
I've tried manually set up numpy in C:\Python37 and reference Numpy.Bare but PythonEngine.BeginAllowThreads();
still force close IIS.
from numpy.net.
can you create a minimal reproduction project and share it on github?
from numpy.net.
@henon https://github.com/normarclone/testNumpy/ here! This is a very minimal project. The code is placed in HomeController and Global.asax file
from numpy.net.
I solved it. You need to wrap all code that accesses numpy in using(Py.GIL()) { ... }
in the controller:
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
//Get 2 sample arrays
double[] Feature1 = JsonConvert.DeserializeObject<List<double>>(Features.Feature1).ToArray();
double[] Feature2 = JsonConvert.DeserializeObject<List<double>>(Features.Feature2).ToArray();
using (Py.GIL())
{
//Convert it to np.array
NDarray arr1 = np.array(Feature1);
NDarray arr2 = np.array(Feature2);
//Process
var result = np.linalg.norm(np.array(arr1 - arr2)).ToString();
//Result : "1.4386139661537802"
return Json(result, JsonRequestBehavior.AllowGet);
}
}
}
from numpy.net.
In the setup you shared on github you had used my Numpy package, which installs python and numpy in the AppData directory. So installing python in C://python37 is not necessary
from numpy.net.
Thank you @henon! Issue close here. Thank you very much π―
from numpy.net.
Related Issues (20)
- np.load of np.savez impossible to get values back out? HOT 3
- np.array leaks memory HOT 12
- Numpy hangs on exit since version 3.10.1.29 (last stable 3.7.1.28) HOT 7
- Support for CuPy HOT 1
- Please Sign and assign StrongName for Numpy Nuget package
- np.split HOT 12
- `Half` type arrays HOT 7
- Set conditions as NDArray Type HOT 3
- fft() failed: βindex -2 is out of bounds for axis 0 with size 1β HOT 9
- Problem with passing imaginery numbers HOT 3
- NDarray of DateTime HOT 3
- Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory HOT 5
- Could not find platform dependent libraries <exec_prefix> HOT 6
- System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'. HOT 5
- Numpy.Bare build for Python 3.11 HOT 3
- np.sum(NDArray, axis:1) not supported? HOT 5
- Unable to use Numpy.NET from linux environment HOT 1
- Hello, has SciSharp/NumSharp stopped development and maintenance? HOT 1
- Unable to cast System.Double[][] to NDarray HOT 2
- failed to use "where" in Numpy.NET HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy.net.