最終我選擇了先檢測OS和安裝合適的Conda發行版,然後根據需要使用Conda輕鬆安裝依賴項,例如
download_miniconda() {
echo "Downloading Miniconda for Python dependencies..."
OS_BIT_TYPE="$(uname -m)"
OS_ARCHITECTURE="$(uname -s)"
if [ $OS_BIT_TYPE == "i686" ]; then
OS_BIT_TYPE="x86"
fi
if [ $OS_ARCHITECTURE == "Darwin" ]; then
OS_ARCHITECTURE="MacOSX"
fi
MINICONDA_INSTALL_FILE="Miniconda2-latest-$OS_ARCHITECTURE-$OS_BIT_TYPE.sh"
MINICONDA_DOWNLOAD_URL="https://repo.continuum.io/miniconda/$MINICONDA_INSTALL_FILE"
$(curl -O $MINICONDA_DOWNLOAD_URL)
$(chmod +x $MINICONDA_INSTALL_FILE)
}
install_miniconda() {
echo "Installing Miniconda..."
echo "$(./$MINICONDA_INSTALL_FILE -b -p $HOME/miniconda)"
echo "$(rm $MINICONDA_INSTALL_FILE)"
}
confirm_miniconda_installed() {
if hash conda 2>/dev/null; then
echo "Miniconda installed!"
else
echo "Failed to install Miniconda. Please visit http://conda.pydata.org/docs/install/quick.html to install and then try rerunning this script, making sure that Miniconda is accessible in the PATH"
fi
}
update_script_startup_file() {
echo "if [[ \":\$PATH:\" != *\":\$HOME/miniconda/bin:\"* ]]; then" >> $STARTUP_FILE
echo " export PATH=\"\$PATH:\$HOME/miniconda/bin\"" >> $STARTUP_FILE
echo "fi" >> $STARTUP_FILE
}
add_miniconda_to_path() {
# temporary update to PATH for this script
export PATH="$PATH:$HOME/miniconda/bin"
# permanent update to PATH for user's convenience
if [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
STARTUP_FILE="$HOME/.bashrc"
update_script_startup_file
elif [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
STARTUP_FILE="$HOME/.zshrc"
update_script_startup_file
else
echo "Couldn't automatically add Miniconda to the PATH of your preferred terminal. We suggest working from Bash or ZShell."
fi
}
create_conda_environment() {
if hash conda 2>/dev/null; then
CONDA_ENVIRONMENTS="$(conda env list)"
if [[ "$CONDA_ENVIRONMENTS" != *"words2map"* ]]; then
conda create --name my_mongo_environment --yes mongo
fi
fi
}
當然,用戶可以更改蒙戈並安裝Conda覆蓋任何依賴,它覆蓋了700+包...
FYI這是對words2map庫更大的安裝序列的一部分,所以任何更新都會反映在那裏。
您可以調用'os_version'函數獲取操作系統名稱和版本 - 請參閱https://github.com/elifarley/shell-lib/blob/master/lib/base.sh – Elifarley
謝謝,我最終這樣做,然後選擇從這些信息建立Conda並更容易地安裝軟件包... – legel