File (@NotNull final String binaryPath) { final File bin = new File(binaryPath).getParentFile(); if (bin != null) { final String rootPath = bin.getParent(); if (rootPath != null) { final File root = new File(rootPath); final File activateThis = new File(bin, "activate_this.py"); // binaryPath should contain an 'activate' script, and root should have bin (with us) and include and libp if (activateThis.exists()) { final File activate = findExecutableFile(bin, "activate"); if (activate != null) { return root; } } // Python 3.3 virtualenvs can be found as described in PEP 405 if (new File(root, "pyvenv.cfg").exists()) { return root; } } } return null; }