{"id":10165,"date":"2025-06-11T10:46:55","date_gmt":"2025-06-11T14:46:55","guid":{"rendered":"https:\/\/labs.icahn.mssm.edu\/minervalab\/?page_id=10165"},"modified":"2026-07-29T15:27:58","modified_gmt":"2026-07-29T19:27:58","slug":"python-and-jupyter-notebook","status":"publish","type":"page","link":"https:\/\/labs.icahn.mssm.edu\/minervalab\/documentation\/python-and-jupyter-notebook\/","title":{"rendered":"Python and Jupyter Notebook"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; fullwidth=&#8221;on&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_fullwidth_menu menu_id=&#8221;15&#8243; menu_style=&#8221;centered&#8221; fullwidth_menu=&#8221;on&#8221; active_link_color=&#8221;#d80b8c&#8221; dropdown_menu_line_color=&#8221;#221f72&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; menu_font=&#8221;|600|||||||&#8221; menu_text_color=&#8221;#FFFFFF&#8221; menu_font_size=&#8221;16px&#8221; background_color=&#8221;#221f72&#8243; background_layout=&#8221;dark&#8221; sticky_position=&#8221;top&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_fullwidth_menu][\/et_pb_section][et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; custom_padding=&#8221;0px||0px||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.16&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; custom_padding=&#8221;||0px||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; custom_padding=&#8221;|||&#8221; global_colors_info=&#8221;{}&#8221; custom_padding__hover=&#8221;|||&#8221;][et_pb_text admin_label=&#8221;Breadcrumb&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p><a href=\"https:\/\/labs.icahn.mssm.edu\/minervalab\/scientific-computing-and-data\/\">Scientific Computing and Data<\/a> \/ <a href=\"https:\/\/labs.icahn.mssm.edu\/minervalab\/\">High Performance Computing<\/a> \/ <a title=\"Documentation\" href=\"https:\/\/labs.icahn.mssm.edu\/minervalab\/documentation\/\">Documentation<\/a> \/ Python and Jupyter Notebook<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section][et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text admin_label=&#8221;Python&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h1>Python and Jupyter Notebook<\/h1>\n<p>&nbsp;<\/p>\n<h2><strong>Contents<\/strong><br \/> <span style=\"color: #00aeef\"><a href=\"#python\">Python<\/a><br \/> <a href=\"#jupyter\">Jupyter Notebook<\/a><\/span><\/h2>\n<p>&nbsp;<\/p>\n<h2><a id=\"python\"><\/a>Python<\/h2>\n<p>Python is an interpreted programming language that has become increasingly popular in high-performance computing environments because it\u2019s available with an assortment of numerical and scientific computing libraries (numpy, scipy, pandas, etc.), relatively easy to learn, open source, and free.<\/p>\n<p>Many versions of Python are available to use on Minerva. To see a list of installed versions of Python on the cluster, use Lmod\u2019s spider command:<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/scpublic.dmz.hpc.mssm.edu\/HPC\/python\/python_modules.jpg&#8221; align=&#8221;center&#8221; admin_label=&#8221;Python Modules Image&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; width=&#8221;60%&#8221; max_width=&#8221;60%&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text admin_label=&#8221;Usage&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h3>Usage<\/h3>\n<p>Python may be run either interactively, or as a batch process reading commands from a script file. To run Python interactively, open an interactive session by submitting a job to the interactive LSF queue. Then simply execute the Python command. After the terminal is launched in the interactive mode, users can run Python commands at the prompt:<\/p>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/scpublic.dmz.hpc.mssm.edu\/HPC\/python\/python_usage.jpg&#8221; align=&#8221;center&#8221; admin_label=&#8221;Python Usage Image&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; width=&#8221;60%&#8221; max_width=&#8221;60%&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text admin_label=&#8221;Install Packages Locally&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p>&nbsp;<\/p>\n<h3>Installing New Packages Locally<\/h3>\n<p>There are multiple ways to install and manage Python packages locally. Here we present several of them in detail below as examples:\u00a0<\/p>\n<p>[\/et_pb_text][et_pb_text admin_label=&#8221;Anaconda&#8221; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; custom_margin=&#8221;20px||||false|false&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<ul>\n<li><b>Using Miniforge3<\/b><\/li>\n<\/ul>\n<p>You can also create a virtual environment using Conda in miniforge3 modules. Please be familiar with <a href=\"https:\/\/docs.conda.io\/projects\/conda\/en\/latest\/user-guide\/tasks\/manage-environments.html\">official Conda user guide<\/a> and <a href=\"https:\/\/labs.icahn.mssm.edu\/minervalab\/documentation\/conda\/#usepython\">our documentation<\/a> for more information about using Conda.<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/scpublic.dmz.hpc.mssm.edu\/HPC\/conda\/miniforge.png&#8221; align=&#8221;center&#8221; admin_label=&#8221;Anaconda3 Image&#8221; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; width=&#8221;60%&#8221; max_width=&#8221;60%&#8221; custom_margin=&#8221;10px||20px||false|false&#8221; custom_padding=&#8221;10px||20px||false|false&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text admin_label=&#8221;Venv&#8221; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<ul>\n<li><b>Using venv<\/b><\/li>\n<\/ul>\n<p><a href=\"https:\/\/docs.python.org\/3\/library\/venv.html\">venv<\/a> allows you to manage separate package installations for different projects. They essentially allow you to create a \u201cvirtual\u201d isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.<\/p>\n<p>Python will need to be loaded in module before using venv:<\/p>\n<blockquote>\n<pre><code>$ ml python<\/code><\/pre>\n<\/blockquote>\n<p>Creation of virtual environments is done by executing the command venv:<\/p>\n<blockquote>\n<pre><code>$ python -m venv <strong>\/path\/to\/new\/virtual\/env<\/strong><\/code><\/pre>\n<\/blockquote>\n<p>venv will create a virtual Python installation in the \u201c\/path\/to\/new\/virtual\/env\u201d folder.<br \/>\nBefore you can start installing or using packages in your virtual environment, you\u2019ll need to activate it:<\/p>\n<blockquote>\n<pre><code>$ unset PYTHONPATH \n$ source <strong>\/path\/to\/new\/virtual\/env\/bin\/activate<\/strong><\/code><\/pre>\n<\/blockquote>\n<p>Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell\u2019s PATH.<br \/>\nYou can confirm you\u2019re in the virtual environment by checking the location of your Python interpreter:<\/p>\n<blockquote>\n<pre><code>$ which python<\/code><\/pre>\n<\/blockquote>\n<p>It should be in the env directory:<\/p>\n<blockquote>\n<pre><code>\/path\/to\/new\/virtual\/env\/bin\/python<\/code><\/pre>\n<\/blockquote>\n<p>The name of the virtual environment will also show in front of your username in the prompt:<\/p>\n<blockquote>\n<pre><code>(<strong>env<\/strong>) [<strong>user_name<\/strong>@li04e01 ~]$<\/code><\/pre>\n<\/blockquote>\n<p>As long as your virtual environment is activated, you can use pip for package installation and pip will install packages into that specific environment by default. You\u2019ll also be able to import and use packages in your Python application.<br \/>\nIf you want to switch projects or otherwise leave your virtual environment, simply run:<\/p>\n<blockquote>\n<pre><code>$ deactivate<\/code><\/pre>\n<\/blockquote>\n<p>If you want to re-enter the virtual environment just follow the same instructions above about activating a virtual environment. There\u2019s no need to re-create the virtual environment.[\/et_pb_text][et_pb_text admin_label=&#8221;Pip&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; custom_padding=&#8221;10px||||false|false&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<ul>\n<li><b>Using pip<\/b><\/li>\n<\/ul>\n<p>Pip is the <a href=\"https:\/\/packaging.python.org\/guides\/tool-recommendations\/\">package installer for Python<\/a>. You can use it to install packages from the <a href=\"https:\/\/pypi.org\/\">Python Package Index<\/a><br \/> and other indexes.<\/p>\n<p>Python will need to be loaded in module before using pip:<\/p>\n<blockquote>\n<pre><code>$ ml python<\/code><\/pre>\n<\/blockquote>\n<p>The syntax of installing a single Python package is:<\/p>\n<blockquote>\n<pre><code>$ pip install --user package_name==version<\/code><\/pre>\n<\/blockquote>\n<p>For example,<\/p>\n<blockquote>\n<pre><code>$ pip install --user numpy==1.21.6<\/code><\/pre>\n<\/blockquote>\n<p>Packages will be installed in:<\/p>\n<blockquote>\n<pre><code>~\/.local\/lib\/python_version\/site-packages\/<\/code><\/pre>\n<\/blockquote>\n<p>For example, for Python 3.12.5, the path is:<\/p>\n<blockquote>\n<pre><code>~\/.local\/lib\/python3.12\/site-packages\/<\/code><\/pre>\n<\/blockquote>\n<p>Then, prepend the package path and bin path to PYTHONPATH and PATH environment variables:<\/p>\n<blockquote>\n<pre><code>$ export PYTHONPATH=~\/.local\/lib\/python_version\/site-packages\/:$PYTHONPATH\r\n&gt;&gt;&gt; $ export PATH=~\/.local\/bin\/:$PATH<\/code><\/pre>\n<\/blockquote>\n<p>You should be able to use the new package now.<\/p>\n<blockquote>\n<pre><code>$ python \r\n&gt;&gt;&gt; import numpy \r\n&gt;&gt;&gt; numpy.__version__ \r\n'1.21.6'<\/code><\/pre>\n<\/blockquote>\n<p>You can also install packages to a specific location by adding the &#8211;prefix:<\/p>\n<blockquote>\n<pre><code>$ pip install --prefix=\/path\/to\/folder package_name==version<\/code><\/pre>\n<\/blockquote>\n<p>You will also need to prepend the paths as shown above:<\/p>\n<blockquote>\n<pre><code>$ export PATH=\/path\/to\/folder\/bin\/:$PATH \r\n$ export PYTHONPATH=\/path\/to\/folder\/lib\/python_version\/site-packages\/:$PYTHONPATH<\/code><\/pre>\n<\/blockquote>\n<p>[\/et_pb_text][et_pb_text admin_label=&#8221;Jupyter&#8221; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|600|||||||&#8221; header_text_color=&#8221;#221f72&#8243; header_font_size=&#8221;26px&#8221; header_2_text_color=&#8221;#221f72&#8243; header_2_font_size=&#8221;24px&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p>&nbsp;<\/p>\n<h2><a id=\"jupyter\"><\/a>Jupyter Notebook<\/h2>\n<p><a href=\"https:\/\/jupyter.org\/\">Jupyter notebooks<\/a> (formerly iPython notebooks) is an interactive computational environment, in which you can code interactively in Python from a web browser with support for equation editing, code execution, rich text, mathematics, inline plotting, rich media etc.<\/p>\n<p>You can access the Jupyter notebook running via <a href=\"https:\/\/labs.icahn.mssm.edu\/minervalab\/documentation\/open-ondemand\/\">Open OnDemand<\/a>.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scientific Computing and Data \/ High Performance Computing \/ Documentation \/ Python and Jupyter NotebookPython and Jupyter Notebook &nbsp; Contents Python Jupyter Notebook &nbsp; Python Python is an interpreted programming language that has become increasingly popular in high-performance computing environments because it\u2019s available with an assortment of numerical and scientific computing libraries (numpy, scipy, pandas, [&hellip;]<\/p>\n","protected":false},"author":624,"featured_media":0,"parent":35,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-10165","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/pages\/10165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/users\/624"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/comments?post=10165"}],"version-history":[{"count":73,"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/pages\/10165\/revisions"}],"predecessor-version":[{"id":14790,"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/pages\/10165\/revisions\/14790"}],"up":[{"embeddable":true,"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/pages\/35"}],"wp:attachment":[{"href":"https:\/\/labs.icahn.mssm.edu\/minervalab\/wp-json\/wp\/v2\/media?parent=10165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}