Excited to get started with using Jupyter notebooks? The most common application for working with Jupyter notebooks is JupyterLab. Jupyter notebooks are great scratch pads for brainstorming ideas, and there are two common ways to use them: locally on our computer or in the cloud.
We recommend the official installation instructions for getting it set up: https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html
Personally, we prefer installing JupyterLab via conda (more on conda in a future episode) via
conda install -c conda-forge jupyterlab
Once you have it installed, you can type jupyter lab
in your terminal and press Enter, and JupyterLab should open automatically in your web browser.
If you prefer working in the cloud, Google Colab is an easy and free way for doing so. You can check it out here.
If you prefer to select your own hardware, we recommend using the Grid.ai platform where you can open JupyterLab directoy from the web browser after you created a session:
We will revist this topic in a future episode! However, if you are curious and can't wait, here is how this works!
A basic Python project can start with a simple folder structure. Of course, the exact structure depends on the use-case context, but most often we start with two folders:
src
for our code files (.py
scripts).docs
for documentation-related files.
A README.md
file also often a good idea for leaving general instructions.
Suppose we have a file mycode.py
that contains our code. We can convert it into a Python package so that we can import functions from it. To do this, we create a folder called mypackage
(and arbitrary naming choice) that contains at least these 2 things:
- A file called
__init__.py
. (This can be empty.) - A file containing our code. We name it
mycode.py
(another arbitary name).
Lastly, we create a setup.py
file with the following minimal contents:
import setuptools
setuptools.setup(
name='mypackage',
version='0.1',
author='sebastian',
packages=setuptools.find_packages(),
)
This setup.py
file should be next to the mypackage
folder. After you created these files, it should look like as follows:
(This starter package is available here on GitHub.)
Now, we are able to install the package using the command
pip install -e path/to/the/folder/containing/setup.py
Finally, after completing this step, we can import code from the package in Python, anywhere on our computer!
Stay tuned for a future episode where we discuss this in more detail! Also, if you have any questions, please don't hesitate to reach out on Slack!
If you have questions or suggestions, please don't hesitate to reach out to William (@_willfalcon) and Sebastian (@rasbt) on Twitter or join our Slack Channel. For more episodes, also check out the Lightning Bits: Engineering for Researchers.