Hello,
I am trying to use SasPy, I have configured it correctly (as far as i can tell) by modifying sascfg.py, but when I run the following code I get a Java error.
Here are the machine specs:
- OS: Windows Server 2012R2
- Java version : "1.6.0_45"
- SAS: 9.4_M2
- Python 3.6, Anaconda distribution
Is this java related - i.e. does SasPy have some minimum Java requirements ? Or is there some other issue that I'm missing?
import saspy
sas = saspy.SASsession(cfgname='winlocal')
Java Error:
java.lang.NoClassDefFoundError: com/sas/services/connection/ConnectionFactoryException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: com.sas.services.connection.ConnectionFactoryException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
6 more
Exception in thread "main"
The type of error returned for an unsupported Java version would be something like this:
>>> sas = saspy.SASsession(cfg='winlocal') Using SAS Config named: winlocal Java Error: java.lang.UnsupportedClassVersionError: pyiom/saspy2j : Unsupported major.minor version 51.0
The type of error you're getting:
Java Error: java.lang.NoClassDefFoundError: com/sas/services/connection/ConnectionFactoryException
indicates an issue with the class paths to the jars rather than the version of Java.
Verify that the class paths in the sascfg.py file are correct. The default paths to the jars under the SASDeploymentManager install directory included in the file almost certainly need to be updated for the maintenance release of SAS running at your site. For example, I had to update mine to reference the correct deploywiz__<version>__ for my SAS release as follows:
# build out a local classpath variable to use below for Windows clients cpW = "C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94502__prt__xx__sp0__1\\deploywiz\\sas.svc.connection.jar" cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94502__prt__xx__sp0__1\\deploywiz\\log4j.jar" cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94502__prt__xx__sp0__1\\deploywiz\\sas.security.sspi.jar" cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94502__prt__xx__sp0__1\\deploywiz\\sas.core.jar"
I think sascfg.py is configured correctly, this is then entire contents of the file:
SAS_config_names=['winlocal']
SAS_config_options = {'lock_down': False,
'verbose' : True
}
SAS_output_options = {'output' : 'html5'}
cpW = "D:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94472__prt__xx__sp0__1\\deploywiz\\sas.svc.connection.jar"
cpW += ";D:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94472__prt__xx__sp0__1\\deploywiz\\log4j.jar"
cpW += ";D:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94472__prt__xx__sp0__1\\deploywiz\\sas.security.sspi.jar"
cpW += ";D:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94472__prt__xx__sp0__1\\deploywiz\\sas.core.jar"
cpW += ";D:\\Anaconda3\\envs\\prod1\\Lib\\site-packages\\saspy\\java\\saspyiom.jar"
winlocal = {'java' : 'D:\\Program Files\\SASHOME\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java',
'encoding' : 'windows-1252',
'classpath' : cpW
}
All files in the cpW dictionary exist at that path. The path in winlocal points to the folder where java.exe and java.dll are located (they are actually in the "bin" folder, but it seems adding "java" at the end is necessary). I tried adding ".exe." and I received the same error.
Hi there. I have only just started looking at these posts on Communities. I've only gotten Issues through my saspy Github site till now.
As it turns out, Java 6 (1.6) is too old to work with saspy. I've hit this issue a few times with other customers and getting a more current version of Java (Java 8 is the 'Current' one if you go to java.com to download) has resolved the problem each time.
And, yes, your config appears perfectly reasonable. I think it is just the old Java.
Tom
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.