22proc Kratos::InstallAllPythonDependencies { } {
33
44 if { $::tcl_platform(platform) == " windows" } { set os win } {set os unix}
5-
6- # Check if python is installed
7- if {[pythonVersion] <= 0} {
5+ set dir [lindex [Kratos::GetLaunchConfigurationFile] 0]
6+ if {$os eq " win" } {set py " python" } {set py " python3" }
7+ # Check if python is installed. minimum 3.5, best 3.9
8+ set python_version [pythonVersion $py ]
9+ if { $python_version <= 0 || [GidUtils::TwoVersionsCmp $python_version " 3.9.0" ] <0 } {
810 if {$os eq " win" } {
911 package require gid_cross_platform
10- gid_cross_platform::run_as_administrator [file join $::Kratos::kratos_private(Path) exec install_python .win.bat ] [ lindex [Kratos::GetLaunchConfigurationFile] 0]
12+ gid_cross_platform::run_as_administrator [file join $::Kratos::kratos_private(Path) exec install_python_and_dependencies .win.bat ] $dir
1113 } {
1214 exec " sudo apt-get install python3.9"
1315 }
1416 }
1517
16- # Check if pip is installed
17- # W [exec python -m pip --version]
18-
19- # Install pip packages
18+ set missing_packages [Kratos::GetMissingPipPackages]
19+ ::GidUtils::SetWarnLine " Installing pip packages $missing_packages "
20+ if {[llength $missing_packages ] > 0} {
21+ exec pyw -m pip install --no-cache-dir --disable-pip-version-check {*}$missing_packages
22+ }
2023}
2124
2225proc Kratos::pythonVersion {{pythonExecutable " python" }} {
2326 # Tricky point: Python 2.7 writes version info to stderr!
27+ set ver 0
2428 catch {
2529 set info [exec $pythonExecutable --version 2>@1]
2630 if {[regexp {^Python ([\d.]+)$} $info --> version]} {
27- return $version
31+ set ver $version
32+ }
33+ }
34+ return $ver
35+ }
36+
37+ proc Kratos::pipVersion { } {
38+ set ver 0
39+ catch {
40+ set info [exec pyw -m pip --version 2>@1]
41+ if {[regexp {^pip ([\d.]+)*} $info --> version]} {
42+ set ver $version
2843 }
2944 }
30- return 0
45+ return $ver
46+ }
47+
48+ proc Kratos::GetMissingPipPackages { } {
49+ set missing_packages [list ]
50+ set pip_packages_required [list KratosMultiphysics KratosFluidDynamicsApplication KratosConvectionDiffusionApplication \
51+ KratosDEMApplication numpy KratosDamApplication KratosSwimmingDEMApplication KratosStructuralApplication KratosMeshMovingApplication \
52+ KratosMappingApplication KratosParticleMechanicsApplication KratosLinearSolversApplication KratosContactStructuralMechanicsApplication]
53+
54+ set pip_packages_installed [list ]
55+ set pip_packages_installed_raw [exec pyw -m pip list --format=freeze --disable-pip-version-check 2>@1]
56+ foreach package $pip_packages_installed_raw {
57+ lappend pip_packages_installed [lindex [split $package " ==" ] 0]
58+ }
59+ foreach required_package $pip_packages_required {
60+ if {$required_package ni $pip_packages_installed } {lappend missing_packages $required_package }
61+ }
62+ return $missing_packages
3163}
3264
3365
@@ -44,8 +76,9 @@ proc Kratos::CheckDependencies { } {
4476 if {[string equal $reply " cancel" ]} {
4577
4678 }
47- }
79+ } else {
4880
81+ }
4982}
5083
5184proc Kratos::GetLaunchConfigurationFile { } {
0 commit comments