using System;using System.IO;using Numpy;namespace CustomInstallLocationExample{class Program{static void Main(string[] args){// ================================================// This example demonstrates how to install Python and Numpy from the assembly's resources// (build action 'Embedded resource') into a custom location (here the local execution directory ".")// and then use Numpy.Bare with that installation.// ================================================// set the installation source to be the embedded python zip from our resourcesPython.Deployment.Installer.Source = new Python.Deployment.Installer.EmbeddedResourceInstallationSource(){Assembly = typeof(Program).Assembly,ResourceName = "python-3.7.3-embed-amd64.zip",};// install in local directory. if you don't set it will install in local app data of your user accountPython.Deployment.Installer.InstallPath = Path.GetFullPath(".");// see what the installer is doingPython.Deployment.Installer.LogMessage += Console.WriteLine;// install from the given sourcePython.Deployment.Installer.SetupPython(force: false).Wait();Python.Deployment.Installer.InstallWheel(typeof(Program).Assembly,"numpy-1.16.3-cp37-cp37m-win_amd64.whl").Wait();// if the installation is local, you don't even need to set the path//Environment.SetEnvironmentVariable("PATH", Path.GetFullPath(@"./python-3.7.3-embed-amd64"), EnvironmentVariableTarget.Process);// Now use Numpy.Barevar a = np.arange(10);Console.WriteLine("a: "+ a.repr);var b = np.arange(10)["::-1"];Console.WriteLine("b: " + b.repr);var a_x_b = np.matmul(a, b);Console.WriteLine("a x b: " + a_x_b.repr);}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。