BookmarkSubscribeRSS Feed
Azeem112
Quartz | Level 8

I have a Python file in which I am using Google Cloud Analytics libraries to perform a task. I am getting data in my SAS code and executing that file via the X command. 

 

My issue is when I execute that file from the command line (CMD) or from IDE (pycharm) that file works perfectly, when I execute that file from sas code I get a dependency error.  I have uninstalled and reinstalled all of the libraries and rechecked that code is working fine. 

 

my sample code is 

 

%let file=fileNm;
%let param=Param1;

%let filepath = python H:\Python_Speech_to_text\main.py &file &param > H:\Python_Speech_to_text\Logs\Log&file..txt;
%put &filepath;

 

 

 

I've tried 

 

Method 1

data _null_;
x "&filepath";
run;

Method 2

 

data _null_;
infile "&filepath" pipe;
input;
put _infile_;
run;

 

 

Method 3

%macro executePython;
   %sysexec %str(H:; &filepath);
%mend executePython;

%executePython;

 

with all the above options I get a Python error in the log file of SAS code that a module is missing but if I copy the result of 

%put &filepath;

and paste it into the CMD file will run smoothly. 

 

5 REPLIES 5
Quentin
Super User

Just to simplify testing, would remove the macro variable stuff and test with everything hardcoded like:

x "python H:\Python_Speech_to_text\main.py fileNm Param1 > H:\Python_Speech_to_text\Logs\LogfileNm.txt" ;

If that command works when you run it from command line, but does not work when you run it from SAS, I think that would suggest that your SAS code is not running on the same computer where you have installed the python packages.

 

For SAS, are you using SAS installed on your local PC, or are you using a client like Enterprise Guide or Studio where you are connecting to a SAS server?  If you are connecting to a SAS server, when you use the X statement it will execute the command on that server, so that you would need to have python and all packages installed there.

 

Could you share an example of the log from running a simple hard coded X statement from SAS, including the statement and the full log?

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Azeem112
Quartz | Level 8

 I have a single-tier SAS Server and the command is working fine on the CMD of this SAS server, When I try to execute the SAS code, it throws the error. Below I am running from the SAS Studio 

 

I am using the infile command because the X command isn't working even though I have allowed XCMD in the configuration. 

 

%let filepath = python H:\Data\Desktop\Python_Speech_to_text\main.py 10060.mp3 en 10060 > H:\Data\Desktop\Python_Speec
h_to_text\Logs\PythonFile100601.txt;

data _null_;
         	infile "&filepath" pipe;
           	input;
           	put _infile_;
run;

Logs

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         %let filepath = python H:\Data\Desktop\Python_Speech_to_text\main.py 10060.mp3 en 10060 > H:\Data\Desktop\Python_Speec
 74         h_to_text\Logs\PythonFile100602.txt;
 75         
 76         data _null_;
 77                  infile "&filepath" pipe;
 78                    input;
 79                    put _infile_;
 80         run;
 
 NOTE: The infile "python H:\Data\Desktop\Python_Speech_to_text\main.py 10060.mp3 en 10060 > H:\Data\Desktop\Python_Speec 
       h_to_text\Logs\PythonFile100602.txt" is:
       Unnamed Pipe Access Device,
       
       PROCESS=python H:\Data\Desktop\Python_Speech_to_text\main.py 10060.mp3 en 10060 > H:\Data\Desktop\Python_Speec 
       h_to_text\Logs\PythonFile100602.txt,
       RECFM=V,LRECL=32767
 
 Stderr output:
 Traceback (most recent call last):
   File "H:\Data\Desktop\Python_Speech_to_text\main.py", line 1, in <module>
     from google.cloud import speech
   File "G:\Python38\lib\site-packages\google\cloud\speech\__init__.py", line 21, in <module>
     from google.cloud.speech_v1.services.adaptation.client import AdaptationClient
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\__init__.py", line 21, in <module>
     from .services.adaptation import AdaptationClient
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\services\adaptation\__init__.py", line 16, in <module>
     from .client import AdaptationClient
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\services\adaptation\client.py", line 49, in <module>
     from google.cloud.speech_v1.services.adaptation import pagers
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\services\adaptation\pagers.py", line 27, in <module>
     from google.cloud.speech_v1.types import cloud_speech_adaptation
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\types\__init__.py", line 16, in <module>
     from .cloud_speech import (
   File "G:\Python38\lib\site-packages\google\cloud\speech_v1\types\cloud_speech.py", line 20, in <module>
     import proto  # type: ignore
 ModuleNotFoundError: No module named 'proto'
 NOTE: 0 records were read from the infile "python H:\Data\Desktop\Python_Speech_to_text\main.py 10060.mp3 en 10060 > 
       H:\Data\Desktop\Python_Speec h_to_text\Logs\PythonFile100602.txt".
 NOTE: PROCEDURE| _DISARM|         STOP| _DISARM| 2023-10-30T07:40:24,212+00:00| _DISARM| WorkspaceServer| _DISARM| SAS| _DISARM| | 
       _DISARM| 27099136| _DISARM| 27099136| _DISARM| 11| _DISARM| 11| _DISARM| 1554| _DISARM| 205908107| _DISARM| 0.031250| 
       _DISARM| 0.773000| _DISARM| 2014270823.440000| _DISARM| 2014270824.213000| _DISARM| 0.015625| _DISARM| | _ENDDISARM 
 NOTE: DATA statement used (Total process time):
       real time           0.77 seconds
       cpu time            0.03 seconds
       
 81         
 82         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 94    

I used "pip list" and the missing module is already installed

 

 

Azeem112_0-1698651962255.png

 

 

 

Quentin
Super User

Googling the error message turns up hits like:

https://github.com/googleapis/google-cloud-python/issues/11637

 

So could be weird python package management conflicts which I wouldn't understand as I'm just a baby python learner.

 

But if the command works from the windows command prompt and does not work via pipe, then I'm lost.  I've never seen that.

 

I've never worked with SAS on a windows server, only linux server.  If the simple X statement isn't working, that's concerning.  You might want to call SAS tech support about that.  But clearly the error you are getting is a python error.

 

Is it possible when you are running the command from the windows command prompt you are a different user than when you run the command from SAS via Studio?  If that were the case, I could imagine it's possible there might be  different packages installed or accessible for different user accounts? If you run "pip list" from SAS via pipe, do you see the same list of packages?  If you CD to the directory from SAS and run DIR, do you see the files with the appropriate permissions?

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Azeem112
Quartz | Level 8

I believe it's because of weird Python packages, I managed to set up Python on a new installation successfully and it's working fine on that new installation. I'll check with packages, maybe uninstall and reinstall everything python related and try again.

 

Thanks for your help

SASKiwi
PROC Star

When you run the python command manually and it works, what Windows folder do you run it from? As a test, try adding the path on the front of the python command you have in SAS. Note you may need to add quotes if there are any spaces in your file path.  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1217 views
  • 1 like
  • 3 in conversation