-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (43 loc) · 2 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (43 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using System.Threading.Tasks;
using Python.Runtime;
namespace Python.Included.Example.NetFramework
{
public class Program
{
public static async Task Main(string[] args)
{
// This example demonstrates how Python.Included is able to automatically install a minimal Python
// environment which it includes as an embedded resource in its .NET assembly file
// Python.Included is currently fixed to Python 3.7.3 amd64 for windows
// If you need a different Python version or platform check out the Python.Installer examples!
// install in local directory
Installer.InstallPath = Path.GetFullPath(".");
// see what the installer is doing
Installer.LogMessage += Console.WriteLine;
// install the embedded python distribution
await Installer.SetupPython();
// install pip3 for package installation
await Installer.TryInstallPip();
// download and install Spacy from the internet
await Installer.PipInstallModule("spacy");
// ok, now use pythonnet from that installation
PythonEngine.Initialize();
// call Python's sys.version to prove we are executing the right version
dynamic sys = Py.Import("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 = Py.Import("os");
Console.WriteLine("### Current working directory:\n\t" + os.getcwd());
Console.WriteLine("### PythonPath:\n\t" + PythonEngine.PythonPath);
// call spacy
dynamic spacy = Py.Import("spacy");
Console.WriteLine("### Spacy version:\n\t" + spacy.__version__);
#if NETFRAMEWORK
Console.WriteLine("Hit any key to exit.");
Console.ReadKey();
#endif
}
}
}