Skip to content

Python Tips

Lars Vilhuber edited this page Jan 13, 2023 · 15 revisions

I have a Jupyter notebook, how do I quickly view its contents?

There are two ways to do this. You will need Python installed. Then

  • To view a HTML version, run jupyter-notebook. This should open a browser window, in which you can navigate to the Jupyter notebook. You should now be able to view it, as well as the output from the last run.
  • To create a PDF version (which can be committed to the repository), run jupyter-nbconvert name.ipynb --to pdf, which requires LaTeX to be installed. This should generate a PDF. [Tested on Linux only]

Best practice to reproduce a Python paper?

You should create a Python environment that is dedicated to the project. See Anaconda instructions as one possible method, venv as another one, though others exist.

Here's venv version in a nutshell (full guide)

  • Ensure venv exists:
pip3 install pyenv
  • Create a new environment
python3 -m venv /path/to/new/virtual/environment

or on Windows (adjust!)

c:\>c:\Python35\python -m venv c:\path\to\myenv

To activate:

source env/bin/activate

To deactivate:

deactivate

Jupyter Notebook on CISER

If using the default "Jupyter" link in the Start Menu, the working directory won't be right. Assuming that you have set your Workspace to U:\Documents\Workspace, the following will create a Jupyter Notebook in the right location (thanks to Louis Liu for creating this Howto)

Search "anaconda prompt" from the start menu. right click on the app when it appears and pin it to the taskbar.

Step 1

Right click on anaconda prompt in the taskbar (looks like a black window, similar to command line or terminal). Right click on "anaconda powershell prompt" in the tasks menu that pops up, and then properties.

Step 2

In the properties window, go to the shortcut tab and change the "Start in:" field to U:\Documents\Workspace or whichever directory you keep your bitbucket repos in. Click apply.

Step 3

Next, click on the anaconda prompt shortcut in the taskbar. When anaconda prompt opens, enter the command "Jupyter notebook"

Step 4

Clone this wiki locally