├── LICENSE ├── README.md ├── Tests ├── Unix_Install_Test1.sh └── Windows_Install_Test1.ps1 ├── Linux_Install.sh ├── OSX_Install.sh └── Windows_Install.ps1 /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 David DeTomaso 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Miniconda-Install 2 | Cross-Platform solution to installing a stand-alone Python application using Miniconda 3 | 4 | The main advantages to this approach is: 5 | - Single command to install 6 | - Install is fully isolated (won't interfere with, or be mixed up by an existing Python install) 7 | - No dependencies needed prior to install 8 | 9 | Here are three scripts (one for each major platform) which can be modified to perform an isolated install of a python application. All that is needed is to configure a few environment variables at the top of the file and then the files can be run by: 10 | 11 | ## OSX or Linux 12 | Download the file into the folder where you want to install the application. Then, open a terminal and run either 13 | 14 | bash Linux_Install.sh 15 | 16 | or 17 | 18 | bash OSX_Install.sh 19 | 20 | depending on which OS you're using. 21 | 22 | ## Windows 23 | Download the file into the folder where you want to install the application. Then open the folder, right-click the file, and select "Run with PowerShell" from the popup menu. 24 | 25 | ## What does it do exactly? 26 | The scripts run the following procedure: 27 | 28 | 1. Download Miniconda installer 29 | 2. Run Miniconda installer to generate an isolated Python install 30 | 3. Install dependencies with Conda (if specified) 31 | 4. Install other dependencies with pip (if specified) 32 | 5. Install a local package archive (if specified) 33 | 6. Add the applications entry point to the path by: 34 | 1. Creating a new folder, Scripts, in the Miniconda directory 35 | 2. Sym-linking the entry script into the new folder 36 | 3. Adding the new folder to the user's path 37 | 38 | Symlinking the script is necessary, otherwise adding the /bin folder in the new python install to the path would also add it's python, conda, and pip applications (making this new install the main python - NOT what we want). 39 | 40 | ## Why do this? Other solutions exist... 41 | There are a number of other solutions for this kind of thing, however none of them worked for my application. I developed these scripts for a project of mine and thought others might find them useful too. 42 | 43 | ### VirtualEnv 44 | VirtualEnv is perfectly fine for developers but if your user isn't very command-line savvy, or is new to Python (maybe they use R, for example) then it's less than ideal. I found it difficult to get the instructions down to a very small number of steps that accounted for the variable state of the system Python install, whether or not pip is installed, whether or not the user had admin privileges, etc. 45 | 46 | ###cx_freeze or PyInstaller 47 | These are great tools, but I was unable to get them to work for my project. I kept running into errors on certain packages and eventually gave up. I'd definitely at least give one of these a go, though, before going the route presented here as your resulting install size will be much lower. 48 | -------------------------------------------------------------------------------- /Tests/Unix_Install_Test1.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Name of application to install 5 | AppName="LinuxTest1" 6 | 7 | # Set your project's install directory name here 8 | InstallDir="LinuxTest1" 9 | 10 | # Dependencies installed by Conda 11 | # Commend out the next line if no Conda dependencies 12 | CondaDeps="click pygments" 13 | 14 | # Install the package from PyPi 15 | # Comment out next line if installing locally 16 | PyPiPackage="autopep8" 17 | 18 | # Local packages to install 19 | # Useful if your application is not in PyPi 20 | # Distribute this with a .tar.gz and use this variable 21 | # Comment out the next line if no local package to install 22 | # LocalPackage="mypackage.tar.gz" 23 | 24 | # Entry points to add to the path 25 | # Comment out the next line of no entry point 26 | # (Though not sure why this script would be useful otherwise) 27 | EntryPoint="autopep8" 28 | 29 | echo 30 | echo "Installing $AppName" 31 | 32 | echo 33 | echo "Installing into: $(pwd)/$InstallDir" 34 | echo 35 | 36 | # Miniconda doesn't work for directory structures with spaces 37 | if [[ $(pwd) == *" "* ]] 38 | then 39 | echo "ERROR: Cannot install into a directory with a space in its path" >&2 40 | echo "Exiting..." 41 | echo 42 | exit 1 43 | fi 44 | 45 | # Test if new directory is empty. Exit if it's not 46 | if [ -d $(pwd)/$InstallDir ]; then 47 | if [ "$(ls -A $(pwd)/$InstallDir)" ]; then 48 | echo "ERROR: Directory is not empty" >&2 49 | echo "If you want to install into $(pwd)/$InstallDir, " 50 | echo "clear the directory first and run this script again." 51 | echo "Exiting..." 52 | echo 53 | exit 1 54 | fi 55 | fi 56 | 57 | # Download and install Miniconda 58 | curl "http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh" -o Miniconda_Install.sh 59 | 60 | bash Miniconda_Install.sh -b -f -p $InstallDir 61 | 62 | # Activate the new environment 63 | PATH="$(pwd)/$InstallDir/bin":$PATH 64 | 65 | # Make the new python environment completely independent 66 | # Modify the site.py file so that USER_SITE is not imported 67 | python -s << END 68 | import site 69 | site_file = site.__file__.replace(".pyc", ".py"); 70 | with open(site_file) as fin: 71 | lines = fin.readlines(); 72 | for i,line in enumerate(lines): 73 | if(line.find("ENABLE_USER_SITE = None") > -1): 74 | user_site_line = i; 75 | break; 76 | lines[user_site_line] = "ENABLE_USER_SITE = False\n" 77 | with open(site_file,'w') as fout: 78 | fout.writelines(lines) 79 | END 80 | 81 | # Install Conda Dependencies 82 | if [[ $CondaDeps ]]; then 83 | conda install $CondaDeps -y 84 | fi 85 | 86 | # Install Package from PyPi 87 | if [[ $PyPiPackage ]]; then 88 | pip install $PyPiPackage -q 89 | fi 90 | 91 | # Install Local Package 92 | if [[ $LocalPackage ]]; then 93 | pip install $LocalPackage -q 94 | fi 95 | 96 | # Add Entry Point to the path 97 | if [[ $EntryPoint ]]; then 98 | 99 | cd $InstallDir 100 | mkdir Scripts 101 | ln -s ../bin/$EntryPoint Scripts/$EntryPoint 102 | 103 | echo "$EntryPoint script installed to $(pwd)/Scripts" 104 | echo 105 | echo "Add folder to path by appending to .bashrc?" 106 | read -p "[y/n] >>> " -r 107 | echo 108 | if [[ ($REPLY == "yes") || ($REPLY == "Yes") || ($REPLY == "YES") || 109 | ($REPLY == "y") || ($REPLY == "Y")]] 110 | then 111 | echo "export PATH=\"$(pwd)/Scripts\":\$PATH" >> ~/.bashrc 112 | echo "Your PATH was updated." 113 | echo "Restart the terminal for the change to take effect" 114 | else 115 | echo "Your PATH was not modified." 116 | fi 117 | 118 | cd .. 119 | fi 120 | 121 | # Cleanup 122 | rm Miniconda_Install.sh 123 | 124 | echo 125 | echo "$AppName Install Successfully" 126 | -------------------------------------------------------------------------------- /Linux_Install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Name of application to install 5 | AppName="YourApplicationName" 6 | 7 | # Set your project's install directory name here 8 | InstallDir="YourApplicationFolder" 9 | 10 | # Dependencies installed by Conda 11 | # Comment out the next line if no Conda dependencies 12 | CondaDeps="numpy scipy scikit-learn pandas" 13 | 14 | # Install the package from PyPi 15 | # Comment out next line if installing locally 16 | PyPiPackage="mypackage" 17 | 18 | # Local packages to install 19 | # Useful if your application is not in PyPi 20 | # Distribute this with a .tar.gz and use this variable 21 | # Comment out the next line if no local package to install 22 | LocalPackage="mypackage.tar.gz" 23 | 24 | # Entry points to add to the path 25 | # Comment out the next line of no entry point 26 | # (Though not sure why this script would be useful otherwise) 27 | EntryPoint="YourApplicationName" 28 | 29 | echo 30 | echo "Installing $AppName" 31 | 32 | echo 33 | echo "Installing into: $(pwd)/$InstallDir" 34 | echo 35 | 36 | # Miniconda doesn't work for directory structures with spaces 37 | if [[ $(pwd) == *" "* ]] 38 | then 39 | echo "ERROR: Cannot install into a directory with a space in its path" >&2 40 | echo "Exiting..." 41 | echo 42 | exit 1 43 | fi 44 | 45 | # Test if new directory is empty. Exit if it's not 46 | if [ -d $(pwd)/$InstallDir ]; then 47 | if [ "$(ls -A $(pwd)/$InstallDir)" ]; then 48 | echo "ERROR: Directory is not empty" >&2 49 | echo "If you want to install into $(pwd)/$InstallDir, " 50 | echo "clear the directory first and run this script again." 51 | echo "Exiting..." 52 | echo 53 | exit 1 54 | fi 55 | fi 56 | 57 | # Download and install Miniconda 58 | set +e 59 | curl "https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh" -o Miniconda_Install.sh 60 | if [ $? -ne 0 ]; then 61 | curl "http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh" -o Miniconda_Install.sh 62 | fi 63 | set -e 64 | 65 | bash Miniconda_Install.sh -b -f -p $InstallDir 66 | 67 | # Activate the new environment 68 | PATH="$(pwd)/$InstallDir/bin":$PATH 69 | 70 | # Make the new python environment completely independent 71 | # Modify the site.py file so that USER_SITE is not imported 72 | python -s << END 73 | import site 74 | site_file = site.__file__.replace(".pyc", ".py"); 75 | with open(site_file) as fin: 76 | lines = fin.readlines(); 77 | for i,line in enumerate(lines): 78 | if(line.find("ENABLE_USER_SITE = None") > -1): 79 | user_site_line = i; 80 | break; 81 | lines[user_site_line] = "ENABLE_USER_SITE = False\n" 82 | with open(site_file,'w') as fout: 83 | fout.writelines(lines) 84 | END 85 | 86 | # Install Conda Dependencies 87 | if [[ $CondaDeps ]]; then 88 | conda install $CondaDeps -y 89 | fi 90 | 91 | # Install Package from PyPi 92 | if [[ $PyPiPackage ]]; then 93 | pip install $PyPiPackage -q 94 | fi 95 | 96 | # Install Local Package 97 | if [[ $LocalPackage ]]; then 98 | pip install $LocalPackage -q 99 | fi 100 | 101 | # Cleanup 102 | rm Miniconda_Install.sh 103 | conda clean -iltp --yes 104 | 105 | # Add Entry Point to the path 106 | if [[ $EntryPoint ]]; then 107 | 108 | cd $InstallDir 109 | mkdir Scripts 110 | ln -s ../bin/$EntryPoint Scripts/$EntryPoint 111 | 112 | echo "$EntryPoint script installed to $(pwd)/Scripts" 113 | echo 114 | echo "Add folder to path by appending to .bashrc?" 115 | read -p "[y/n] >>> " -r 116 | echo 117 | if [[ ($REPLY == "yes") || ($REPLY == "Yes") || ($REPLY == "YES") || 118 | ($REPLY == "y") || ($REPLY == "Y")]] 119 | then 120 | echo "export PATH=\"$(pwd)/Scripts\":\$PATH" >> ~/.bashrc 121 | echo "Your PATH was updated." 122 | echo "Restart the terminal for the change to take effect" 123 | else 124 | echo "Your PATH was not modified." 125 | fi 126 | 127 | cd .. 128 | fi 129 | 130 | echo 131 | echo "$AppName Install Successfully" 132 | -------------------------------------------------------------------------------- /OSX_Install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Name of application to install 5 | AppName="YourApplicationName" 6 | 7 | # Set your project's install directory name here 8 | InstallDir="YourApplicationFolder" 9 | 10 | # Dependencies installed by Conda 11 | # Comment out the next line if no Conda dependencies 12 | CondaDeps="numpy scipy scikit-learn pandas" 13 | 14 | # Install the package from PyPi 15 | # Comment out next line if installing locally 16 | PyPiPackage="mypackage" 17 | 18 | # Local packages to install 19 | # Useful if your application is not in PyPi 20 | # Distribute this with a .tar.gz and use this variable 21 | # Comment out the next line if no local package to install 22 | LocalPackage="mypackage.tar.gz" 23 | 24 | # Entry points to add to the path 25 | # Comment out the next line of no entry point 26 | # (Though not sure why this script would be useful otherwise) 27 | EntryPoint="YourApplicationName" 28 | 29 | echo 30 | echo "Installing $AppName" 31 | 32 | echo 33 | echo "Installing into: $(pwd)/$InstallDir" 34 | echo 35 | 36 | # Miniconda doesn't work for directory structures with spaces 37 | if [[ $(pwd) == *" "* ]] 38 | then 39 | echo "ERROR: Cannot install into a directory with a space in its path" >&2 40 | echo "Exiting..." 41 | echo 42 | exit 1 43 | fi 44 | 45 | # Test if new directory is empty. Exit if it's not 46 | if [ -d $(pwd)/$InstallDir ]; then 47 | if [ "$(ls -A $(pwd)/$InstallDir)" ]; then 48 | echo "ERROR: Directory is not empty" >&2 49 | echo "If you want to install into $(pwd)/$InstallDir, " 50 | echo "clear the directory first and run this script again." 51 | echo "Exiting..." 52 | echo 53 | exit 1 54 | fi 55 | fi 56 | 57 | # Download and install Miniconda 58 | set +e 59 | curl "https://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh" -o Miniconda_Install.sh 60 | if [ $? -ne 0 ]; then 61 | curl "http://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh" -o Miniconda_Install.sh 62 | fi 63 | set -e 64 | 65 | bash Miniconda_Install.sh -b -f -p $InstallDir 66 | 67 | # Activate the new environment 68 | PATH="$(pwd)/$InstallDir/bin":$PATH 69 | 70 | # Make the new python environment completely independent 71 | # Modify the site.py file so that USER_SITE is not imported 72 | python -s << END 73 | import site 74 | site_file = site.__file__.replace(".pyc", ".py"); 75 | with open(site_file) as fin: 76 | lines = fin.readlines(); 77 | for i,line in enumerate(lines): 78 | if(line.find("ENABLE_USER_SITE = None") > -1): 79 | user_site_line = i; 80 | break; 81 | lines[user_site_line] = "ENABLE_USER_SITE = False\n" 82 | with open(site_file,'w') as fout: 83 | fout.writelines(lines) 84 | END 85 | 86 | # Install Conda Dependencies 87 | if [[ $CondaDeps ]]; then 88 | conda install $CondaDeps -y 89 | fi 90 | 91 | # Install Package from PyPi 92 | if [[ $PyPiPackage ]]; then 93 | pip install $PyPiPackage -q 94 | fi 95 | 96 | # Install Local Package 97 | if [[ $LocalPackage ]]; then 98 | pip install $LocalPackage -q 99 | fi 100 | 101 | # Cleanup 102 | rm Miniconda_Install.sh 103 | conda clean -iltp --yes 104 | 105 | # Add Entry Point to the path 106 | if [[ $EntryPoint ]]; then 107 | 108 | cd $InstallDir 109 | mkdir Scripts 110 | ln -s ../bin/$EntryPoint Scripts/$EntryPoint 111 | 112 | echo "$EntryPoint script installed to $(pwd)/Scripts" 113 | echo 114 | echo "Add folder to path by appending to .bash_profile?" 115 | read -p "[y/n] >>> " -r 116 | echo 117 | if [[ ($REPLY == "yes") || ($REPLY == "Yes") || ($REPLY == "YES") || 118 | ($REPLY == "y") || ($REPLY == "Y")]] 119 | then 120 | echo "export PATH=\"$(pwd)/Scripts\":\$PATH" >> ~/.bash_profile 121 | echo "Your PATH was updated." 122 | echo "Restart the terminal for the change to take effect" 123 | else 124 | echo "Your PATH was not modified." 125 | fi 126 | 127 | cd .. 128 | fi 129 | 130 | echo 131 | echo "$AppName Install Successfully" 132 | -------------------------------------------------------------------------------- /Tests/Windows_Install_Test1.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop" 2 | 3 | # Name of application to install 4 | $AppName="WindowsTest1" 5 | 6 | # Set your project's install directory name here 7 | $InstallDir="WindowsTest1" 8 | 9 | # Dependencies installed by Conda 10 | # Commend out the next line if no Conda dependencies 11 | $CondaDeps="click","pygments" 12 | 13 | # Dependencies installed with pip instead 14 | # Comment out the next line if no PyPi dependencies 15 | $PyPiPackage="autopep8" 16 | 17 | # Local packages to install 18 | # Useful if your application is not in PyPi 19 | # Distribute this with a .tar.gz and use this variable 20 | # Comment out the next line if no local package to install 21 | # $LocalPackage="mypackage.tar.gz" 22 | 23 | # Entry points to add to the path 24 | # Comment out the next line of no entry point 25 | # (Though not sure why this script would be useful otherwise) 26 | $EntryPoint="autopep8" 27 | 28 | Write-Host ("`nInstalling $AppName to "+(get-location).path+"\$InstallDir") 29 | 30 | 31 | # Download Latest Miniconda Installer 32 | Write-Host "`nDownloading Miniconda Installer...`n" 33 | 34 | (New-Object System.Net.WebClient).DownloadFile("https://repo.continuum.io/miniconda/Miniconda-latest-Windows-x86_64.exe", "$pwd\Miniconda_Install.exe") 35 | 36 | # Install Python environment through Miniconda 37 | Write-Host "Installing Miniconda...`n" 38 | Start-Process Miniconda_Install.exe "/S /AddToPath=0 /D=$pwd\$InstallDir" -Wait 39 | 40 | # Install Dependences to the new Python environment 41 | $env:Path = "$pwd\$InstallDir\Scripts;" + $env:Path 42 | 43 | # Make the new python environment completely independent 44 | # Modify the site.py file so that USER_SITE is not imported 45 | $site_program = @" 46 | import site 47 | site_file = site.__file__.replace('.pyc', '.py'); 48 | with open(site_file) as fin: 49 | lines = fin.readlines(); 50 | for i,line in enumerate(lines): 51 | if(line.find('ENABLE_USER_SITE = None') > -1): 52 | user_site_line = i; 53 | break; 54 | lines[user_site_line] = 'ENABLE_USER_SITE = False\n' 55 | with open(site_file,'w') as fout: 56 | fout.writelines(lines) 57 | "@ 58 | python -c $site_program 59 | 60 | if(Test-Path variable:CondaDeps) 61 | { 62 | Write-Host "Installing Conda dependencies...`n" 63 | conda install $CondaDeps -y 64 | } 65 | 66 | if(Test-Path variable:PyPiPackage) 67 | { 68 | Write-Host "Installing PyPi dependencies...`n" 69 | pip install $PyPiPackage 70 | } 71 | 72 | if(Test-Path variable:LocalPackage) 73 | { 74 | Write-Host "Installing Local package...`n" 75 | pip install $LocalPackage 76 | } 77 | 78 | # Add Entry Point to path 79 | 80 | if(Test-Path variable:EntryPoint) 81 | { 82 | # Move entry-point executable to an isolated folder 83 | $script_folder = "$pwd\$InstallDir\PathScripts" 84 | New-Item $script_folder -type directory | Out-Null 85 | Move-Item $pwd\$InstallDir\Scripts\$EntryPoint.exe $script_folder 86 | 87 | # Ask user if they want to update path 88 | $title = "Update Path" 89 | $message = "`nDo you want to add the $EntryPoint script to your User PATH?" 90 | 91 | $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", ` 92 | "Prepends the User PATH variable with the location of the $EntryPoint script" 93 | 94 | $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", ` 95 | "User PATH is not modified" 96 | 97 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) 98 | 99 | $result = $host.ui.PromptForChoice($title, $message, $options, 0) 100 | 101 | if($result -eq 0) 102 | { 103 | # Update the user's path 104 | $old_path = (Get-ItemProperty -Path HKCU:\Environment).Path 105 | $new_path = $script_folder + ";" + $old_path 106 | cmd /c "setx PATH $new_path" 107 | Set-ItemProperty -Path HKCU:\Environment -Name PATH -Value $new_path 108 | Write-Host "User PATH has been updated" 109 | Write-Host "Open a new command prompt to see the change." 110 | } 111 | else 112 | { 113 | Write-Host "User PATH was not modified.`n" 114 | Write-Host "You may want to add the $EntryPoint script to your path." 115 | Write-Host "It is located in: $script_folder`n" 116 | } 117 | } 118 | 119 | # Cleanup 120 | Remove-Item "Miniconda_Install.exe" 121 | 122 | Write-Host "`n$AppName Successfully Installed" 123 | 124 | Write-Host "Press any key to continue ..." 125 | 126 | $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 127 | -------------------------------------------------------------------------------- /Windows_Install.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop" 2 | 3 | # Name of application to install 4 | $AppName="YourApplicationName" 5 | 6 | # Set your project's install directory name here 7 | $InstallDir="YourApplicationFolder" 8 | 9 | # Dependencies installed by Conda 10 | # Commend out the next line if no Conda dependencies 11 | $CondaDeps="numpy","scipy","scikit-learn","pandas" # some examples 12 | 13 | # Dependencies installed with pip instead 14 | # Comment out the next line if no PyPi dependencies 15 | $PyPiPackage="mypackage" 16 | 17 | # Local packages to install 18 | # Useful if your application is not in PyPi 19 | # Distribute this with a .tar.gz and use this variable 20 | # Comment out the next line if no local package to install 21 | $LocalPackage="mypackage.tar.gz" 22 | 23 | # Entry points to add to the path 24 | # Comment out the next line of no entry point 25 | # (Though not sure why this script would be useful otherwise) 26 | $EntryPoint="YourApplicationName" 27 | 28 | Write-Host ("`nInstalling $AppName to "+(get-location).path+"\$InstallDir") 29 | 30 | 31 | # Download Latest Miniconda Installer 32 | Write-Host "`nDownloading Miniconda Installer...`n" 33 | 34 | (New-Object System.Net.WebClient).DownloadFile("https://repo.continuum.io/miniconda/Miniconda-latest-Windows-x86_64.exe", "$pwd\Miniconda_Install.exe") 35 | 36 | # Install Python environment through Miniconda 37 | Write-Host "Installing Miniconda...`n" 38 | Start-Process Miniconda_Install.exe "/S /AddToPath=0 /D=$pwd\$InstallDir" -Wait 39 | 40 | # Install Dependences to the new Python environment 41 | $env:Path = "$pwd\$InstallDir\Scripts;" + $env:Path 42 | 43 | # Make the new python environment completely independent 44 | # Modify the site.py file so that USER_SITE is not imported 45 | $site_program = @" 46 | import site 47 | site_file = site.__file__.replace('.pyc', '.py'); 48 | with open(site_file) as fin: 49 | lines = fin.readlines(); 50 | for i,line in enumerate(lines): 51 | if(line.find('ENABLE_USER_SITE = None') > -1): 52 | user_site_line = i; 53 | break; 54 | lines[user_site_line] = 'ENABLE_USER_SITE = False\n' 55 | with open(site_file,'w') as fout: 56 | fout.writelines(lines) 57 | "@ 58 | python -c $site_program 59 | 60 | if(Test-Path variable:CondaDeps) 61 | { 62 | Write-Host "Installing Conda dependencies...`n" 63 | conda install $CondaDeps -y 64 | } 65 | 66 | if(Test-Path variable:PyPiPackage) 67 | { 68 | Write-Host "Installing PyPi dependencies...`n" 69 | pip install $PyPiPackage 70 | } 71 | 72 | if(Test-Path variable:LocalPackage) 73 | { 74 | Write-Host "Installing Local package...`n" 75 | pip install $LocalPackage 76 | } 77 | 78 | # Cleanup 79 | Remove-Item "Miniconda_Install.exe" 80 | conda clean -iltp --yes 81 | 82 | # Add Entry Point to path 83 | 84 | if(Test-Path variable:EntryPoint) 85 | { 86 | # Move entry-point executable to an isolated folder 87 | $script_folder = "$pwd\$InstallDir\PathScripts" 88 | New-Item $script_folder -type directory | Out-Null 89 | Move-Item $pwd\$InstallDir\Scripts\$EntryPoint.exe $script_folder 90 | 91 | # Ask user if they want to update path 92 | $title = "Update Path" 93 | $message = "`nDo you want to add the $EntryPoint script to your User PATH?" 94 | 95 | $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", ` 96 | "Prepends the User PATH variable with the location of the $EntryPoint script" 97 | 98 | $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", ` 99 | "User PATH is not modified" 100 | 101 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) 102 | 103 | $result = $host.ui.PromptForChoice($title, $message, $options, 0) 104 | 105 | if($result -eq 0) 106 | { 107 | # Update the user's path 108 | $old_path = (Get-ItemProperty -Path HKCU:\Environment).Path 109 | $new_path = $script_folder + ";" + $old_path 110 | cmd /c "setx PATH $new_path" 111 | Set-ItemProperty -Path HKCU:\Environment -Name PATH -Value $new_path 112 | Write-Host "User PATH has been updated" 113 | Write-Host "Open a new command prompt to see the change" 114 | } 115 | else 116 | { 117 | Write-Host "User PATH was not modified.`n" 118 | Write-Host "You may want to add the $EntryPoint script to your path." 119 | Write-Host "It is located in: $script_folder`n" 120 | } 121 | } 122 | 123 | Write-Host "`n$AppName Successfully Installed" 124 | 125 | Write-Host "Press any key to continue ..." 126 | 127 | $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 128 | --------------------------------------------------------------------------------