Skip to content

Commit caee5b5

Browse files
authored
Follow-up on Ansys Python installations (#97)
1 parent 1c77405 commit caee5b5

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/ansys/tools/installer/constants.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
LOG = logging.getLogger(__name__)
1010
LOG.setLevel("DEBUG")
11-
ANSYS_ENV_VAR_START = "awp_root"
12-
ANSYS_SUPPORTED_PYTHON_VERSIONS = ["3_7", "3_10"]
13-
1411

1512
ABOUT_TEXT = f"""<h2>Ansys Python Installer {__version__}</h2>
1613
<p>Created by the PyAnsys Team.</p>
@@ -28,13 +25,16 @@
2825

2926
ANSYS_VENVS = ".ansys_python_venvs"
3027

28+
ANSYS_ENV_VAR_START = "awp_root"
29+
30+
ANSYS_SUPPORTED_PYTHON_VERSIONS = ["3_7", "3_10"]
31+
3132
INSTALL_TEXT = """Choose to use either the standard Python install from <a href='https://www.python.org/'>python.org</a> or <a href='https://github.com/conda-forge/miniforge'>miniforge</a>."""
3233

3334
PYTHON_VERSION_TEXT = """Choose the version of Python to install.
3435
3536
While choosing the latest version of Python is generally recommended, some third-party libraries and applications may not yet be fully compatible with the newest release. Therefore, it is recommended to try the second newest version, as it will still have most of the latest features and improvements while also having broader support among third-party packages."""
3637

37-
3838
PYTHON_VERSION_SELECTION_FOR_VENV = """Choose the version of Python to use for your virtual environment.
3939
4040
Please select the Python version from the table below to create its respective virtual environment."""
@@ -59,6 +59,7 @@
5959

6060

6161
ASSETS_PATH = os.path.join(THIS_PATH, "assets")
62+
6263
ANSYS_FAVICON = os.path.join(ASSETS_PATH, "ansys-favicon.png")
6364

6465
PYANSYS_DOCS_SITES = {

src/ansys/tools/installer/find_python.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,39 +105,34 @@ def _find_installed_python_win(admin=False):
105105

106106

107107
def _find_installed_ansys_win():
108-
"""Check the environment variables for ansys installation."""
109-
env_keys = list()
108+
"""Check the environment variables for Ansys installations."""
109+
env_keys = []
110110
for key in os.environ.keys():
111111
if key.lower().startswith(ANSYS_ENV_VAR_START):
112112
env_keys.append(key)
113113
return env_keys
114114

115115

116116
def _find_installed_ansys_python_win():
117-
"""Check the ansys installation folder for installed Python."""
117+
"""Check the Ansys installation folder for installed Python."""
118118
installed_ansys = _find_installed_ansys_win()
119119
paths = {}
120-
ansys_python_path_items = [
121-
"commonfiles",
122-
"CPython",
123-
"<platform>",
124-
"winx64",
125-
"Release",
126-
"python",
127-
"python.exe",
128-
]
129120
for ansys_ver_env_key in installed_ansys:
130121
ansys_path = os.environ[ansys_ver_env_key]
131-
for supp_py_ver in ANSYS_SUPPORTED_PYTHON_VERSIONS:
132-
ansys_python_path_items[2] = supp_py_ver
133-
path = os.path.join(ansys_path, *ansys_python_path_items)
122+
for ansys_py_ver in ANSYS_SUPPORTED_PYTHON_VERSIONS:
123+
path = os.path.join(
124+
ansys_path,
125+
f"commonfiles\\CPython\\{ansys_py_ver}\\winx64\\Release\\python",
126+
)
134127
if os.path.exists(path):
135128
version_output = subprocess.check_output(
136-
[path, "--version"], text=True
129+
[f"{path}\\python.exe", "--version"], text=True
137130
).strip()
138-
version = version_output.split()[1]
139-
if version is not None and path is not None:
131+
try:
132+
version = version_output.split()[1]
140133
paths[path] = (version, False)
134+
except Exception:
135+
pass
141136

142137
return paths
143138

0 commit comments

Comments
 (0)