Skip to content

Commit

Permalink
Update jupyter and add how to run with pycharm
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Nov 20, 2023
1 parent a95b61e commit a5fc354
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
Binary file added docs/python/img/jupyter-pycharm-install.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/python/img/jupyter-pycharm-run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions docs/python/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@

Installing and using Python as recommended below has major benefits and will prevent problems in the future.

!!! warning
!!! warning ":simple-windows: Windows: use the python.org version!"

pyenv was created for macOS and Linux, and although it has a Windows version (called "**pyenv-win**"), this is not working very well and the installation is buggy.

Therefore, for Windows we recommend you install Python "the normal way" ([downloading from python.org](https://www.python.org/downloads/), but we **strongly recommend** you use [virtual environments](venv.md).
Therefore, for Windows we recommend you install Python "the normal way" ([downloading from python.org](https://www.python.org/downloads/)), but we **strongly recommend** you use [virtual environments](venv.md).

---

We recommend installing and managing Python using "pyenv".
pyenv is a tool that allows you to install *multiple versions* of Python, and select which specific version should be used.


=== ":simple-apple: macOS"
To install Python via pyenv, make sure you have [Homebrew](../computer/packagemanager.md) installed and then run the following commands in your [terminal](../computer/terminal.md).

Expand Down
55 changes: 38 additions & 17 deletions docs/python/jupyter.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@

# Jupyter Lab & Notebooks

If you are working with Python, a great way to develop your code efficiently, especially when performing data analysis or creating POCs, is to use Jupyter notebooks. Here we are showing you how to do this through Jupyter lab, which is a web-based, interactive development environment that includes Jupyter notebooks.
If you are working with Python, a great way to develop your code efficiently, especially when performing data analysis or creating proof-of-concepts, is to use [Jupyter notebooks](https://jupyter.org/).
Here we are showing you how to do this through Jupyter lab, which is a web-based, interactive development environment that includes Jupyter notebooks.


# How to install:

In your terminal/Powershell you can use `pip` to install Jupyter Lab.
# How to install & launch

```bash
pip install jupyterlab
```
=== "Using the terminal"
In your [terminal](../computer/terminal.md), you can use `pip` to install Jupyter Lab packages.

# How to launch:
```bash
pip install jupyterlab
```

Then you can launch the application with:
Then you can launch the application with:

```bash
jupyter lab
```
```bash
jupyter lab
```

This will start Jupyter Lab on your browser. On the left panel you can navigate through your files and directories. The right panel is the Launcher; from here you can start a notebook, as shown below.
This will start Jupyter Lab in your internet browser (eg Firefox/Chrome/Safari).
On the left panel you can navigate through your files and directories. The right panel is the Launcher; from here you can start a notebook, as shown below.

![Interface](img/jupyter-1.png)
![Interface](img/jupyter-1.png)

# How to work with a notebook

Within the new notebook, you can write small blocks of code in separate cells and run them individually by pressing `SHIFT+ENTER`. You can move cells around and collapse them, plot graphs and images and you can even add [Markdown](../../docs/writing/markdown.md) cells to document your process.
=== "Using PyCharm"

!!! warning
This does **not** not with the free version of PyCharm (Community Edition).
You need the [Professional Edition](https://www.jetbrains.com/pycharm/) (free for students).

In PyCharm, open a project where you have one or more `*.ipynb` files and then install "jupyterlab" and "jupyter" packages:

![](img/jupyter-pycharm-install.png){:width="500px"}

and then you can simply run press Run/Play to run the cell that is currently selected, and you can select the one you want with the mouse.

![](img/jupyter-pycharm-run.png)


## How to work with a notebook

Within the new notebook, you can write small blocks of code in separate cells and run them individually by pressing `SHIFT+ENTER`. You can move cells around and collapse them, plot graphs and images and you can even add [Markdown](../writing/markdown.md) cells to document your process.

![Interface](img/jupyter-2.png)

The biggest advantage of the notebook is that you do not need to rerun parts of code that might be time-consuming (eg loading a large TIF file). Once a cell is run, its state is preserved and subsequent cells can be changed and run independently.

As shown below, you can use a exclamation mark to run Bash commands (for example for installing a new python module to your environment) and a question mark to see some information about you functions an variables.
!!! info
The biggest advantage of the notebook is that you do not need to rerun parts of code that might be time-consuming (eg loading a large TIF file). Once a cell is run, its state is preserved and subsequent cells can be changed and run independently.

As shown below, you can use a exclamation mark to run bash commands (for example for installing a new python module to your environment) and a question mark to see some information about you functions an variables.

![Tips](img/jupyter-3.png)

0 comments on commit a5fc354

Please sign in to comment.