mirror of
https://github.com/spiritLHLS/one-click-installation-script.git
synced 2024-11-16 21:43:37 +08:00
Update jupyter.sh
This commit is contained in:
parent
84787dd85a
commit
fc3f7fea0c
89
jupyter.sh
89
jupyter.sh
|
@ -23,44 +23,29 @@ echo "有安装则提示是否需要修改用户名和密码,否则则自动
|
||||||
echo "最后都会打印jupyter的信息,如果本机最后有jupyter的话,无论是通过何种途径安装的"
|
echo "最后都会打印jupyter的信息,如果本机最后有jupyter的话,无论是通过何种途径安装的"
|
||||||
|
|
||||||
install_jupyter() {
|
install_jupyter() {
|
||||||
# Update package manager and install required packages
|
rm -rf Miniconda3-latest-Linux-x86_64.sh*
|
||||||
if command -v apt-get &> /dev/null; then
|
|
||||||
sudo apt-get update
|
# Check if conda is already installed
|
||||||
sudo apt-get install -y python3 python3-pip python3-dev build-essential libssl-dev libffi-dev
|
if ! command -v conda &> /dev/null; then
|
||||||
elif command -v dnf &> /dev/null; then
|
# Install conda
|
||||||
sudo dnf update
|
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
|
||||||
sudo dnf install -y python3 python3-pip python3-devel openssl-devel libffi-devel
|
bash Miniconda3-latest-Linux-x86_64.sh -u
|
||||||
elif command -v yum &> /dev/null; then
|
# bash Miniconda3-latest-Linux-x86_64.sh
|
||||||
sudo yum update
|
|
||||||
sudo yum install -y python3 python3-pip python3-devel openssl-devel libffi-devel
|
# Add conda to PATH
|
||||||
elif command -v zypper &> /dev/null; then
|
echo 'export PATH="$PATH:$HOME/miniconda3/bin:$HOME/miniconda3/condabin"' >> ~/.bashrc
|
||||||
sudo zypper update
|
echo 'export PATH="$PATH:$HOME/.local/share/jupyter"' >> ~/.bashrc
|
||||||
sudo zypper install -y python3 python3-pip python3-devel openssl-devel libffi-devel
|
source ~/.bashrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install virtualenv
|
# Create a new conda environment and install jupyter
|
||||||
pip3 install --upgrade virtualenv
|
conda create -n jupyter-env python=3
|
||||||
|
source activate jupyter-env
|
||||||
# Create virtual environment for Jupyter Notebook
|
conda install jupyter jupyterlab
|
||||||
virtualenv jupyter-env
|
|
||||||
|
|
||||||
# Activate the virtual environment
|
|
||||||
source jupyter-env/bin/activate
|
|
||||||
|
|
||||||
# Install Jupyter Notebook and Jupyter Lab
|
|
||||||
pip3 install jupyter jupyterlab
|
|
||||||
|
|
||||||
# Add Jupyter Notebook to PATH
|
|
||||||
echo 'export PATH="$PATH:$(python3 -m site --user-base)/bin"' >> ~/.bashrc
|
|
||||||
source ~/.bashrc
|
|
||||||
|
|
||||||
# Generate a config file for Jupyter Notebook
|
|
||||||
jupyter notebook --generate-config
|
|
||||||
|
|
||||||
# Copy the config file to jupyter_server_config.py
|
|
||||||
cp ~/.jupyter/jupyter_notebook_config.py ~/.jupyter/jupyter_server_config.py
|
|
||||||
|
|
||||||
# Set username and password for Jupyter Notebook
|
# Set username and password for Jupyter Notebook
|
||||||
|
jupyter notebook --generate-config
|
||||||
|
cp ~/.jupyter/jupyter_notebook_config.py ~/.jupyter/jupyter_server_config.py
|
||||||
echo "c.NotebookApp.password = 'spiritlhl'" >> ~/.jupyter/jupyter_server_config.py
|
echo "c.NotebookApp.password = 'spiritlhl'" >> ~/.jupyter/jupyter_server_config.py
|
||||||
echo "c.NotebookApp.username = 'spiritlhl'" >> ~/.jupyter/jupyter_server_config.py
|
echo "c.NotebookApp.username = 'spiritlhl'" >> ~/.jupyter/jupyter_server_config.py
|
||||||
|
|
||||||
|
@ -72,11 +57,14 @@ install_jupyter() {
|
||||||
sudo firewall-cmd --reload
|
sudo firewall-cmd --reload
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start Jupyter Notebook with port 13692
|
# Start Jupyter Notebook with port 13692 and host 0.0.0.0
|
||||||
jupyter lab --port 13692 --no-browser
|
jupyter lab --port 13692 --no-browser --ip=0.0.0.0
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
change_username_and_password() {
|
change_username_and_password() {
|
||||||
# Prompt the user for a new username and password
|
# Prompt the user for a new username and password
|
||||||
reading "Enter a new username: " username
|
reading "Enter a new username: " username
|
||||||
|
@ -132,6 +120,35 @@ query_jupyter_info() {
|
||||||
# Extract port
|
# Extract port
|
||||||
port=$(echo "$config" | grep "c.NotebookApp.port" | awk -F "=" '{print $2}' | tr -d ' ')
|
port=$(echo "$config" | grep "c.NotebookApp.port" | awk -F "=" '{print $2}' | tr -d ' ')
|
||||||
echo "Port: $port"
|
echo "Port: $port"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_jupyter() {
|
||||||
|
# Deactivate the virtual environment
|
||||||
|
deactivate
|
||||||
|
|
||||||
|
# Remove the virtual environment
|
||||||
|
rm -rf jupyter-env
|
||||||
|
|
||||||
|
# Uninstall Jupyter Notebook and Jupyter Lab
|
||||||
|
pip3 uninstall jupyter jupyterlab
|
||||||
|
|
||||||
|
# Remove Jupyter Notebook from PATH
|
||||||
|
sed -i '/export PATH="$PATH:$(python3 -m site --user-base)\/bin"/d' ~/.bashrc
|
||||||
|
source ~/.bashrc
|
||||||
|
|
||||||
|
# Remove Jupyter Notebook config files
|
||||||
|
rm -rf ~/.jupyter
|
||||||
|
|
||||||
|
# Remove port 13692 from firewall
|
||||||
|
if command -v ufw &> /dev/null; then
|
||||||
|
sudo ufw delete allow 13692/tcp
|
||||||
|
elif command -v firewall-cmd &> /dev/null; then
|
||||||
|
sudo firewall-cmd --remove-port=13692/tcp --permanent
|
||||||
|
sudo firewall-cmd --reload
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user