Select to view content in your preferred language

Problem with running python with even only import arcpy from C# Web API

403
1
02-04-2022 06:53 AM
WilliamYip
New Contributor II

We met problem with running python file.  I am not sure if we have did wrong with any environment setting.

ArcGIS Pro 2.8 installed with arcpy

1. A c# API calls a batch file

2. Then, the batch file calls a python script

Problem happened that it all failed with no return when arcpy import included. But, we can run successfully with no arcpy included. So, we verified that python can be executed when without arcpy.

 

 

Code for c# API

Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
//start.WorkingDirectory = @"D:\script",
FileName = @"D:\script\pythontest.bat",
Arguments = "",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Log.Information("python output=" + output);

Code for pythontest.bat batch file

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy" myscript.py

Code for myscript.py

import sys

import arcpy

 

0 Kudos
1 Reply
by Anonymous User
Not applicable

What license do you have for the Pro installation?  arcpy also has to be licensed, so it may be failing on not being able to be licensed.  You can wrap the imports into a try/except and log the exception that happens when it tries to import arcpy.

0 Kudos