0
votes

In python IDE, i run these two code snippets and get different output for the java version:

stdout,stderr = Popen(['java','-version'], shell=False,   stderr=PIPE).communicate()
print(stderr)

java version "1.7.0" Java(TM) SE Runtime Environment (build pwi3270sr8fp10-20141219_01(SR8 FP10)) IBM J9 VM (build 2.6, JRE 1.7.0 Windows 7 x86-32 20141216_227497 (JIT enabled, AOT enabled) J9VM - R26_Java726_SR8_20141216_0955_B227497 JIT - r11.b07_20141003_74578.05 GC - R26_Java726_SR8_20141216_0955_B227497 J9CL - 20141216_227497) JCL - 20141217_01 based on Oracle jdk7u75-b12

os.system("java -version")

java version "1.8.0_40" Java(TM) SE Runtime Environment (build 1.8.0_40-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

Why do i get a different java version inside my python IDE (PyCharm)? How can i change it?

1

1 Answers

1
votes

I think this is because os.system() uses the shell (so will pick up any changes in .bashrc / .profile etc... Are you setting a different Java location in your $PATH / $JAVA_HOME in any of those?

I believe Popen doesn't invoke a shell (unless you set shell=true).

Disclaimer: Not tested this.