Using VS 2019 I installed the nuget packages IronPython v2.7.11 and DynamicLanguageRuntime v1.3.0 and am trying to run a python script. It ran fine until I added imports to the script:
import requests, time, socket
import random
Here’s the C#:
static void Main(string[] args)
{
DateTime start = DateTime.Now;
ScriptEngine engine = Python.CreateEngine();
var searchPaths = engine.GetSearchPaths();
// Path to where everything is installed for this Python enviroment
searchPaths.Add(@"C:\Users\George\.conda\envs\spenv2");
int url_id = 1701;
string url = "https://www.yellowpages.com/search?search_terms=Health&geo_location_terms=Aliso+Viejo%2C+CA";
ScriptScope scope = engine.CreateScope();
engine.ExecuteFile(@"D:\Apps\Data Destinations\Scraping\ScrapeProjects\Job1.v4_For_IronPython_CSharp\ScrapeUrlPages.py", scope);
dynamic testFunction = scope.GetVariable("scrape_all_pages_for_this_search");
dynamic result = testFunction(url_id, url);
Console.WriteLine(result);
}
I found a few posts regarding similar issues and the solution most of them was to add search paths. Which I did:
searchPaths.Add(@"C:\Users\George\.conda\envs\spenv2");
This is where everything is installed for the Python environment, spendv2, is being used. Any recommendations on what I need to do? Thank you.
I know that this is an old post, but I found something that works for me that can help in future questions about this.
IronPython.StdLib from the NuGet Package.Tkinter) with my IDE (PyCharm) and then I added the folder to the Lib folder in my C# project.var libs = new[] {@"{PATH OF YOUR PROJECT}\Lib"};
engine.SetSearchPaths(libs);
And that works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With