在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:kleinee/jns开源软件地址:https://github.com/kleinee/jns开源编程语言:Shell 89.5%开源软件介绍:Jupyter Notebook & Lab Server on Raspberry PiIntroProject Jupyter not only revolutionizes data-heavy research across domains - it also boosts personal productivity for problems on a much smaller scale. Due to openness it is an amazing platform for exploring concepts and learning new things. I started setting up a Jupyter Notebook Server on a Raspberry Pi following this blog post by Arun Durvasula. Convinced of the potential of the platform I followed the development. My personal exercise soon taught me a great deal about the underlying architcture. Given Jupyter's complexity, speed of growth and scale, it is remarkable that such a system runs fine on a Raspberry Pi. This repository isn't really anything genuine: I owe big thanks to many contributors in the Jupyter, Raspberry Pi, Linux, Python, Julia and greater Open Source communities for providing all the beautiful building blocks - small and large. What is new?
What do you need to follow along?
InstallationIMPORTANT NOTE on fresh installations
First boot with fresh SD card
sudo apt install -y git
sudo sed -i -e 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=2048/' /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
git clone https://github.com/kleinee/jns
cd ~/jns/scripts Technically you can now run You might not want all features on your system. Feel free to edit `inst_jns.sh' to suit your requirements. Install required Raspbian packages with aptsudo ./prep.sh A couple of packages from the Raspbian repository are required during installation and later for a some Python packages to work properly. The script just fetches these packages and installs them. #!/bin/bash
# script name: prep.sh
# last modified: 2018/09/09
# sudo: yes
script_name=$(basename -- "$0")
if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$script_name"
exit 1
fi
apt update && apt -y upgrade
apt -y install pandoc
apt -y install libxml2-dev libxslt-dev
apt -y install libblas-dev liblapack-dev
apt -y install libatlas-base-dev gfortran
apt -y install libtiff5-dev libjpeg62-turbo-dev
apt -y install zlib1g-dev libfreetype6-dev liblcms2-dev
apt -y install libwebp-dev tcl8.5-dev tk8.5-dev
apt -y install libharfbuzz-dev libfribidi-dev
apt -y install libhdf5-dev
apt -y install libnetcdf-dev
apt -y install python3-pip
apt -y install python3-venv
apt -y install libzmq3-dev
apt -y install sqlite3 Install required Python 3 packages with pip./inst_stack.sh
#!/bin/bash
# script name: inst_stack.sh
# last modified: 2018/01/14
# sudo: no
script_name=$(basename -- "$0")
env="/home/pi/.venv/jns"
if [ $(id -u) = 0 ]
then
echo "usage: ./$script_name"
exit 1
fi
if [ ! -d "$venv" ]; then
python3 -m venv $env
fi
# activate virtual environment
source $env/bin/activate
pip3 install pip==9.0.0
pip3 install setuptools
pip3 install -U pip
cat requirements.txt | xargs -n 1 pip3 install Configure Jupyter./conf_jupyter.sh With this script you generate a jupyter notebook configuration directory and in it a file called
NOTE: This setup still uses password authentication. If you prefer token-based authentication, you have to change settings in the config file After the basic configuration the script activates the bash kernel and activates extensions for Jupyter Notebook and JupyterLab. At the JupyterLab end this requires intstallation of #!/bin/bash
# script name: conf_jupyter.sh
# last modified: 2018/09/09
# sudo: no
script_name=$(basename -- "$0")
env="/home/pi/.venv/jns"
if [ $(id -u) = 0 ]
then
echo "usage: ./$script_name"
exit 1
fi
# activate virtual environment
source $env/bin/activate
# generate config and create notebook directory
# if notebook directory exists, we keep it (-p)
# if configuration file exeists, we overwrite it (-y)
jupyter notebook -y --generate-config
cd $home
mkdir -p notebooks
target=~/.jupyter/jupyter_notebook_config.py
# set up dictionary of changes for jupyter_config.py
declare -A arr
app='c.NotebookApp'
arr+=(["$app.open_browser"]="$app.open_browser = False")
arr+=(["$app.ip"]="$app.ip ='*'")
arr+=(["$app.port"]="$app.port = 8888")
arr+=(["$app.enable_mathjax"]="$app.enable_mathjax = True")
arr+=(["$app.notebook_dir"]="$app.notebook_dir = '/home/pi/notebooks'")
arr+=(["$app.password"]="$app.password = 'sha1:5815fb7ca805:f09ed218dfcc908acb3e29c3b697079fea37486a'")
# apply changes to jupyter_notebook_config.py
for key in ${!arr[@]};do
if grep -qF $key ${target}; then
# key found -> replace line
sed -i "/${key}/c ${arr[${key}]}" $target
else
# key not found -> append line
echo "${arr[${key}]}" >> $target
fi
done
# install bash kernel
python3 -m bash_kernel.install
# install extensions
jupyter serverextension enable --py jupyterlab
jupyter nbextension enable --py widgetsnbextension --sys-prefix
jupyter nbextension enable --py --sys-prefix bqplot
# activate clusters tab in notebook interface
/home/pi/.venv/jns/bin/ipcluster nbextension enable --user
# install nodejs and node version manager n
# if node is not yet installed
if which node > /dev/null
then
echo "node is installed, skipping..."
else
# install nodejs and node version manager n
cd ~/jns
# fix for issue #22
# install nodejs and node version manager n
# see: https://github.com/mklement0/n-install
curl -L https://git.io/n-install | bash -s -- -y lts
fi
# install jupyter lab extensions
bash -i ./inst_lab_ext.sh The script #!/bin/bash
# script name: inst_lab_ext.sh
# last modified: 2019/04/06
# sudo: no
script_name=$(basename -- "$0")
env="/home/pi/.venv/jns"
if [ $(id -u) = 0 ]
then
echo "usage: ./$script_name"
exit 1
fi
. /home/pi/.bashrc
. $env/bin/activate
jupyter lab clean
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
jupyter labextension install bqplot --no-build
jupyter labextension install jupyterlab_bokeh --no-build
jupyter labextension install jupyter-leaflet --no-build
jupyter lab build Start and access your serverActivate the virtual environmentSince you used a virtual environment to install Python modules, you need to activate this environment before you can start your server: source /home/pi/.venv/jns/bin/activate The prompt will change to indicate successfull activation preceding (jns) pi@zerow:~ $ Before you proceedAfter installation completes, you will still need to activate the change made to You can be accomplish this by any of the following:
That's the reason for this warning during node installation:
You can see this by running the following commands after your installation completes: pi@test-pi:~/jns $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pi@test-pi:~/jns $ . ~/.bashrc
pi@test-pi:~/jns $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/n/bin
pi@test-pi:~/jns $ If you look at your $PATH environment variable and see /home/pi/n/bin you are ready to use node. Also note that if you uninstall node with Start the serverTo start your server just type Access the serverTo access your server form a webbrowser on a computer running on the same network as your Raspberry Pi, just open a browser and use the Pi's IP address / port 8888 as the url. xxx.xxx.xxx.xxx:8888 Change `xxx.xxx.xxx.xxx' to the IP address of the Raspberry Pi. LoginDuring the configuration the default password for the server was set to (jns) pi@zerow:~ $ jupyter notebook password
Enter password: ****
Verify password: **** Install TeX (optional)sudo ./inst_tex.sh
#!/bin/bash
# script name: inst_tex.sh
# last modified: 2018/03/11
# sudo: yes
script_name=$(basename -- "$0")
if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$script_name"
exit 1
fi
#------------------------------------------------------
apt install -y texlive-xetex
apt install -y latexmk
#------------------------------------------------------ Install Julia and the IJulia kernel (optional)
Alternative 1: Julia 1.1.0 (RECOMMENDED)sudo ./inst_julia-1.1.0.sh
The Download HelperAs per comments in the script this is literally a 1:1 copy of code found on stack overflow - adjustments were only necessary to set the FILE_ID and the DESTINATION as required in the context of this repository. The helper is called by the installer script and is not meant to be exceuted manually. #!/home/pi/.venv/jns/bin/python
#
# last modified 2019/05/26
#
# Python helper script to download Julia 1.1.0 binaries
# not meant to be executed manually
# https://stackoverflow.com/questions/38511444/python-download-files-from-google-drive-using-url
#
FILE_ID = '1fj6pNAJgmUD7bsSXqh8ocC1wESx8jkRh'
DESTINATION = './julia-1.1.0-arm32bit.zip'
import requests
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
if __name__ == "__main__":
file_id = FILE_ID
destination = DESTINATION
download_file_from_google_drive(file_id, destination) The InstallerNote that the code assumes that julia is not present.
#!/bin/bash
# script name: inst_julia-1.1.0.sh
# last modified: 2019/05/26
# sudo: yes
SCRIPT_NAME=$(basename -- "$0")
JNS_USER='pi'
HOME_DIR="/home/$JNS_USER"
ENV="$HOME_DIR/.venv/jns"
JULIA_HOME=$HOME_DIR/julia/
if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$SCRIPT_NAME"
exit 1
fi
#
# apt install dependencies
#
apt install -y build-essential
apt install -y libatomic1
apt install -y gfortran
apt install -y perl
apt install -y wget
apt install -y m4
apt install -y cmake
apt install -y pkg-config
apt install -y libopenblas-base libopenblas-dev
apt install -y libatlas3-base libatlas-base-dev
apt install -y liblapack-dev
apt install -y libmpfr-dev libgmp3-dev
apt install -y libgfortran3
#
# download and install julia based on architecture
#
su pi <<ONE
cd $HOME_DIR
. $ENV/bin/activate
./dnld_julia-1.1.0-arm32bit.py
unzip ./julia-1. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论