-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_and_install_numpy.py
More file actions
45 lines (38 loc) · 1.34 KB
/
check_and_install_numpy.py
File metadata and controls
45 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import sys
import subprocess
import importlib
def check_and_install(package_name):
def get_version(name):
try:
module = importlib.import_module(name)
version = getattr(module, '__version__', 'unknown')
print(f"{name} is already installed. Version: {version}")
return True
except ImportError:
print(f"{name} is not installed.")
return False
# First check
if get_version(package_name):
return
# Locate mayapy.exe
maya_exe_path = sys.executable
maya_dir = os.path.dirname(maya_exe_path)
mayapy_path = os.path.join(maya_dir, "mayapy.exe")
if not os.path.exists(mayapy_path):
print("mayapy.exe not found. Cannot proceed with installation.")
return
# Attempt to install
try:
print(f"Installing {package_name} using mayapy...")
subprocess.check_call([mayapy_path, "-m", "pip", "install", package_name])
except subprocess.CalledProcessError as e:
print(f"Error occurred while installing {package_name}:", e)
return
# Final check after installation
print("Checking installation result...")
if get_version(package_name):
print(f"{package_name} installed successfully.")
else:
print(f"Failed to install {package_name}.")
check_and_install("numpy")