Skip to content

Commit 96401dc

Browse files
install python packages
1 parent 5ef31b0 commit 96401dc

3 files changed

Lines changed: 58 additions & 12 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@echo off
2+
cd %1
3+
echo "Installing python 3.9.9 from www.python.org"
4+
rem --Download python installer
5+
rem Curl is included in windows since 2018
6+
curl -ssL "https://www.python.org/ftp/python/3.9.9/python-3.9.9-amd64.exe" -o python-installer.exe
7+
8+
rem --Install python
9+
python-installer.exe /quiet InstallAllUsers=1 PrependPath=1
10+
del python-installer.exe
11+
echo "Python 3.9.9 installed"
12+
13+
pause

kratos.gid/scripts/Launch.tcl

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,64 @@
22
proc 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

2225
proc 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

5184
proc Kratos::GetLaunchConfigurationFile { } {

kratos.gid/scripts/Menus.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ proc Kratos::ChangeMenus { } {
151151
if {[GidUtils::VersionCmp "14.1.4d"] <0 } { set cmd [list ChangeVariables kratos_preferences] } {set cmd [list PreferencesWindow kratos_preferences]}
152152
GiDMenu::InsertOption "Kratos" [list "Kratos preferences" ] [incr pos] PRE $cmd "" "" replace =
153153
GiDMenu::InsertOption "Kratos" [list "View current log" ] [incr pos] PREPOST [list Kratos::ViewLog] "" "" replace =
154-
GiDMenu::InsertOption "Kratos" [list "Install python and dependencies" ] [incr pos] PREPOST [list Kratos::InstallAllPythonDependencies] "" "" replace =
154+
GiDMenu::InsertOption "Kratos" [list "Install python and dependencies" ] [incr pos] PREPOST [list Kratos::CheckDependencies] "" "" replace =
155155
GiDMenu::InsertOption "Kratos" [list "About Kratos" ] [incr pos] PREPOST [list Kratos::About] "" "" replace =
156156
GidChangeDataLabel "Data units" ""
157157
GidChangeDataLabel "Interval" ""

0 commit comments

Comments
 (0)