-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example project that installs multiple wheels
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Python.Runtime; | ||
|
||
namespace Python.Deployment.InstallWheel | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
// ================================================ | ||
// This example demonstrates how to embed a Python distribution (v3.8.5) and install it locally | ||
// ================================================ | ||
|
||
// set the installation source to be the embedded python zip from our resources | ||
Python.Deployment.Installer.Source = new 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 account | ||
Python.Deployment.Installer.InstallPath = Path.GetFullPath("."); | ||
|
||
// see what the installer is doing | ||
Python.Deployment.Installer.LogMessage += Console.WriteLine; | ||
|
||
|
||
// install from the given source | ||
await Python.Deployment.Installer.SetupPython(force:true); | ||
|
||
await Python.Deployment.Installer.InstallWheel(typeof(Program).Assembly, | ||
"numpy-1.16.3-cp37-cp37m-win_amd64.whl"); | ||
|
||
// ok, now use pythonnet from that installation | ||
PythonEngine.Initialize(); | ||
|
||
// call Python's sys.version to prove we are executing the right version | ||
dynamic sys=PythonEngine.ImportModule("sys"); | ||
Console.WriteLine("### Python version:\n\t" + sys.version); | ||
|
||
// call os.getcwd() to prove we are executing the locally installed embedded python distribution | ||
dynamic os = PythonEngine.ImportModule("os"); | ||
Console.WriteLine("### Current working directory:\n\t" + os.getcwd()); | ||
Console.WriteLine("### PythonPath:\n\t" + PythonEngine.PythonPath); | ||
|
||
PythonEngine.Exec(@" | ||
import sys | ||
import math | ||
import numpy as np | ||
print ('Hello world!') | ||
print ('version:' + sys.version) | ||
np.arange(1) # check if numpy is properly loaded | ||
a1 = np.arange(60000).reshape(300, 200) | ||
a2 = np.arange(80000).reshape(200, 400) | ||
result = np.matmul(a1, a2) | ||
print('result: ' + str(result)) | ||
"); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/Python.Deployment.InstallWheel/Python.Deployment.InstallWheel.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Remove="numpy-1.16.3-cp37-cp37m-win_amd64.whl" /> | ||
<None Remove="python-3.7.3-embed-amd64.zip" /> | ||
<None Remove="python-3.8.5-embed-amd64.zip" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="numpy-1.16.3-cp37-cp37m-win_amd64.whl" /> | ||
<EmbeddedResource Include="python-3.7.3-embed-amd64.zip" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="pythonnet_netstandard_py37_win" Version="2.5.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\Python.Deployment\Python.Deployment.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Binary file added
BIN
+11.4 MB
examples/Python.Deployment.InstallWheel/numpy-1.16.3-cp37-cp37m-win_amd64.whl
Binary file not shown.
Binary file not shown.