Introduction
Have you ever need to install from scratch a new python and Jupyter environment ?
You may have been wondering where to start, and how to avoid breaking your Python system installation.
So here I have for you a step-by-step installation to get a clean python Jupyter notebook environment.
Step 1: install pyenv
pyenv is my favorite python environment manager.
It enables to safely install multiple versions of python in your OS.
In Ubuntu, I did the following (prerequisites: curl and git):
curl https://pyenv.run | bash
Then, following pyenv documentation, I configured my .bashrc file:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
and restarted my shell:
exec "$SHELL"
I installed python build dependencies:
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \
\
libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
Step 2: install python and create your virtual environment
At this stage, I was ready to install new python versions, such as the version 3.11:
pyenv install 3.10
Then you create a virtual environment:
pyenv virtualenv 3.10.13 nbdev310
Once the virtual env is ready, you can activate it:
pyenv activate nbdev310
Step 3: install Jupyter and other tools
You can install Jupyter, and the nbdev library with pip:
pip install jupyter nbdev
I also recommend to install quarto:
nbdev_install_quarto
Your first nbdev project
Initiate your github repository
You create a new github repository. Once this is done, copy its HTTPS clone url.
Clone your repository in your development environment:
git clone YOUR_REPOSITORY_HTTPS_URL
Configure the nbdev environment
Now you can set-up the initial nbdev environment with:
nbdev_new
nbdev_install_hooks
git add .
git commit -m 'Creation'
git push
PyPi Configuration
To be able to publish your packages to PyPi, register at pypi, and then create a file called ~/.pypirc with your login details. It should have these lines:
[pypi]
username = your_pypi_username
password = your_pypi_password
Congratulations you have a working nbdev environment in a completely isolated environment with chroot and python virtual environment ! You can now enjoy the power of Jupyter notebooks and nbdev library.
Next Steps
You can now continue with the nbdev walkthough.
You can explore the nbdev features: github pages workflow integration, pypi integration, etc.
Enjoy coding with nbdev !