DATA Step, Macro, Functions and more

Executing python script in SAS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Executing python script in SAS

Hi,

I am using SAS 9.4 64 bit on linux and having trouble executing Python scripts through SAS.  The code is

X python /data/xlsx.py -n Sheet1 /data/test.xlsx;

 

which throws the following error message

Traceback (most recent call last):
   File "/data/xlsx.py", line 26, in <module>
     import csv, datetime, zipfile, string, sys, os, re, signal
   File "/opt/rh/python27/root/usr/lib64/python2.7/zipfile.py", line 6, in <module>
     import io
   File "/opt/rh/python27/root/usr/lib64/python2.7/io.py", line 51, in <module>
     import _io
ImportError: /opt/rh/python27/root/usr/lib64/python2.7/lib-dynload/_io.so: undefined symbol: _PyErr_ReplaceException

 

Running "python /data/xlsx.py -n Sheet1 /data/test.xlsx" from the terminal command line works perfectly as expected.  What is going wrong when running from SAS?

 

Thanks!


Accepted Solutions
Solution
‎09-06-2017 05:27 AM
Super User
Posts: 13,913

Re: Executing python script in SAS

This is a guess but the first thing I would check are the paths involved. Fully qualified paths from mount point, drive or what ever basis the OS likes seems to work more consitently.

I believe the X command may be executing from a different directory and that location does not have one or more of /data/xlsx.py or /data/test.xlsx from that location.

View solution in original post


All Replies
Solution
‎09-06-2017 05:27 AM
Super User
Posts: 13,913

Re: Executing python script in SAS

This is a guess but the first thing I would check are the paths involved. Fully qualified paths from mount point, drive or what ever basis the OS likes seems to work more consitently.

I believe the X command may be executing from a different directory and that location does not have one or more of /data/xlsx.py or /data/test.xlsx from that location.

Super User
Super User
Posts: 8,272

Re: Executing python script in SAS

How is SAS installed on your Linux machine? Are you actually running SAS on the same machine that you typed the command to launch it? Or are your using a grid environment where the SAS process is actually running on some other node?

It is possible that the environment that is setup to run SAS is not compatible with the environment that your Python installation needs. If could be as simple as it is finding a different version of Python installed on the machine that is running SAS than the machine that you used to test the Python code. Or it could be related to search paths and load library paths or java versions or other complexities.

 

I find you can usually get better error messages in your SAS log if you run the os commands using a PIPE instead of using the X, SYSTEM, %SYSEXEC options.  But I doubt it will help in your case.

 

data _null_;
  infile "python /data/xlsx.py -n Sheet1 /data/test.xlsx" pipe;
  input;
  put _infile_;
run;

 

 

 

 

Super User
Posts: 2,504

Re: Executing python script in SAS

Are you missing the quotes

?

 

X "python /data/xlsx.py -n Sheet1 /data/test.xlsx";

 

I would use the infile statement as shown in the post above, to get the messages in SAS.

Occasional Contributor
Posts: 8

Re: Executing python script in SAS

Thank you ballardw, Tom and chrisNZ for your replies.

 

ChrisNZ: yes I tried the quotes but didn't work for me unfortunately.

Tom: that command is useful as running the X statement by itself doesn't reveal too much

ballardw: your suggestion fixed the problem.  What I had to do was change the command to this (after a bit of research on how to find where all the executable paths are)

X /usr/bin/python2 /data/xlsx.py -n Sheet1 /data/test.xlsx;

 

Thanks again!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1919 views
  • 0 likes
  • 4 in conversation