BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
reecec
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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.

Tom
Super User Tom
Super User

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;

 

 

 

 

ChrisNZ
Tourmaline | Level 20

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.

reecec
Fluorite | Level 6

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!

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
  • 4 replies
  • 9552 views
  • 0 likes
  • 4 in conversation