@@ -156,7 +156,8 @@ public static String getCommandOutput(String[] cmd, FileObject projectDir) throw
156156 if (projectDir != null ) {
157157 p .directory (FileUtil .toFile (projectDir ));
158158 }
159- return IOUtils .toString (p .start ().getInputStream (), StandardCharsets .UTF_8 ).strip ();
159+ return IOUtils .toString (p .redirectErrorStream (true ).start ().getInputStream (),
160+ StandardCharsets .UTF_8 ).strip ();
160161 }
161162
162163 public static String getPythonStdLibPath (String path ) throws IOException {
@@ -262,10 +263,10 @@ public static ImageIcon getPynguinIcon() {
262263
263264 }
264265
265- public static Properties getProperties (@ NonNull Project project ) throws IOException {
266+ public static Properties getProperties (@ NonNull Project project , boolean isCreating ) throws IOException {
266267
267268 Properties prop = new Properties ();
268- if (OpenProjects .getDefault ().isProjectOpen (project )) {
269+ if (OpenProjects .getDefault ().isProjectOpen (project ) || isCreating ) {
269270 File file = createProperties (project );
270271 prop .load (new FileInputStream (file ));
271272 }
@@ -274,12 +275,7 @@ public static Properties getProperties(@NonNull Project project) throws IOExcept
274275 }
275276
276277 public static String getVersion (String projectPythonExe ) throws IOException {
277- String commandOutput = getCommandOutput (new String []{projectPythonExe , "--version" }, null );
278- //Python 2 print CLI output to stderr instead of stdout causing the version to not be retrieved
279- if (commandOutput .isEmpty () && projectPythonExe .contains ("python2" )) {
280- commandOutput = "Python 2" ;
281- }
282- return commandOutput ;
278+ return getCommandOutput (new String []{projectPythonExe , "--version" }, null );
283279 }
284280
285281 public static ImageIcon getErrorIcon () {
@@ -491,7 +487,7 @@ public static void manageRunEnvs(ProcessBuilder pb) {
491487
492488 public static String getVenv (PythonProject get ) {
493489 try {
494- return getProperties (get ).getProperty ("nbproject.virtualmanager" , "venv" );
490+ return getProperties (get , false ).getProperty ("nbproject.virtualmanager" , "venv" );
495491 } catch (IOException ex ) {
496492 Exceptions .printStackTrace (ex );
497493 }
0 commit comments