简体   繁体   中英

how to run python script which contains third party libraries using c#.Net?

I have created a python script, which consists of third party dll's. if i run it's executed properly. if run python script from c# application, i got an issue as shown below "No module named expat; use SimpleXMLTreeBuilder instead"

How can i rectify that one.

I am using import gdata.client library in my python script.

and my c# code is:

var engine = Python.CreateEngine();
var paths = engine.GetSearchPaths();
paths.Add(@"c:\Subbu\PythonPractise\Sample\gdata-2.0.18\src");
paths.Add(@"c:\Subbu\PythonPractise\Sample\gdata-2.0.18");
paths.Add(@"C:\Python27\Lib");
engine.SetSearchPaths(paths);
dynamic py = engine.ExecuteFile(@"D:\Subbu\PythonPractise\API\SampleAPI.py");

You should add reference to assembly that you are trying to use. From C# it would look something like this:

engine.Runtime.LoadAssembly(Assembly.LoadFile(@"Path\to\assemblyFile"));

or from python script:

import clr
clr.AddReferenceToFileAndPath("path\\to\\assemblyFile")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM