Difference between revisions of "Python"

From UFRC
Jump to navigation Jump to search
(Remove link to obsolete personal modules page)
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Software]][[Category:Language]][[Category:Programming]]
[[Category:Software]][[Category:Languages]][[Category:Bioinformatics]]
 
 
{|
 
{|
 
<!--Main settings - REQUIRED-->
 
<!--Main settings - REQUIRED-->
|{{#vardefine:app|python3}}
+
|{{#vardefine:app|python}}
 
|{{#vardefine:url|http://python.org}}
 
|{{#vardefine:url|http://python.org}}
 
|{{#vardefine:exe|1}} <!--Present manual instructions for running the software -->
 
|{{#vardefine:exe|1}} <!--Present manual instructions for running the software -->
Line 19: Line 18:
 
{{App_Description|app={{#var:app}}|url={{#var:url}}|name={{#var:app}}}}|}}
 
{{App_Description|app={{#var:app}}|url={{#var:url}}|name={{#var:app}}}}|}}
  
Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. Python version 3 is the current implementation of Python while python2 is a legacy version that will be unsupported after 2020. See the [http://www.python3statement.org/ statement about the move of major scientific projects to python3]
+
Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. Python version 3 is the current implementation of Python while python2 is a legacy version no longer supported after 2020-01-01.
==Python3 vs Python3-Core==
+
 
The <code>python3</code> environment module provides a full-featured python3 installation with around 300 installed python3 modules for development and use of python3 applications for research. If you only need the core python3 build to provide a scripting interface for the application you are building see the <code>[[Python3-core|python3-core]]</code> environment module.
+
==Environment Modules==
<!--Modules-->
+
Run <code>module spider {{#var:app}}</code> to find out what environment modules are available for this application.
==Required Modules==
 
[[Modules|modules documentation]]
 
===Serial===
 
*{{#var:app}}
 
 
==System Variables==
 
==System Variables==
* HPC_{{#uppercase:{{#var:app}}}}_DIR - installation directory
+
* HPC_{{uc:{{#var:app}}}}_DIR - installation directory
  
 
* HPC_PYTHON_BIN - executable directory
 
* HPC_PYTHON_BIN - executable directory
Line 35: Line 30:
 
<!--Additional-->
 
<!--Additional-->
 
{{#if: {{#var: exe}}|==Additional Information==
 
{{#if: {{#var: exe}}|==Additional Information==
* After the appropriate environment module is loaded - type "python3" at the command line to open an interactive session.
+
* After the appropriate environment module is loaded - type "python" at the command line to open an interactive session.
* To run a python3 script type <code>python3 scriptname.py</code>. If the correct "shebang" line is used at the top of the script E.g.
+
* To run a python script type <code>python scriptname.py</code>. If the correct "shebang" line is used at the top of the script E.g.
  #!/usr/bin/env python3
+
  #!/usr/bin/env python
then the script can be run directly as <code>scriptname.py</code> if it's in the executable path or as <code>./scriptname.py</code> if it's in the current directory. The same rules apply to using a python3 script in a batch job script.
+
then the script can be run directly as <code>scriptname.py</code> if it's in the executable path or as <code>./scriptname.py</code> if it's in the current directory. The same rules apply to using a python script in a batch job script.
  
 
You can request installation of additional modules by {{Fileabug}}.
 
You can request installation of additional modules by {{Fileabug}}.
  
;Matplotlib backend note
+
See also: [[Managing Python environments and Jupyter kernels]]
If you are trying to use matplotlib and get an error similar to  
+
 
import _tkinter # If this fails your Python may not be configured for Tk
+
===Matplotlib backend===
ImportError: No module named _tkinter
+
If you are trying to use matplotlib and get an error similar to either of the following:
then you should try the following:
+
*<pre>ImportError: No module named _tkinter</pre>
 +
*<pre>This application failed to start because no Qt platform plugin could be initialized.</pre>
 +
then you should try the following before importing pyplot from matplotlib:
 
  import matplotlib
 
  import matplotlib
 
  matplotlib.use('Agg')
 
  matplotlib.use('Agg')
before importing pyplot from matplotlib.
+
===Output Buffering===
 +
If your job starts, but doesn't appear to produce output from 'print' statements in the job log for a long time, but you want to see that output immediately then turn off output buffering. You can either add a <code>flush=True</code> argument to the print calls you are interested in or run the script with
 +
srun --unbuffered python SCRIPT.py
 +
}}
  
}}
 
 
==Available modules==
 
==Available modules==
To see all installed modules names load the environment module and run <code>pip3 list</code> or <code>python3 -c "help('modules')"</code> command before submitting a request for a new module installation. Below is a list of modules and versions installed in the default python3 version.
+
* To see all installed modules names load the environment module and run <code>pip list</code> or <code>python -c "help('modules')"</code> command before submitting a request for a new module installation.
 +
* To install their own packages, users can load any module that has python within and run <code>pip install "package"</code>.
 +
* Users can define an install path by running: <code>pip install --install-option="--prefix=/some/path/" package_name</code>.
 +
 
 +
Below is a list of modules and versions installed in the default python version.
 +
<div class="mw-collapsible mw-collapsed" style="width:70%; padding: 5px; border: 1px solid gray;">
 +
''Expand this section to view list of available modules.''
 +
<div class="mw-collapsible-content" style="padding: 5px;">
 
{{:Python_Modules}}
 
{{:Python_Modules}}
 +
</div>
 +
</div>
 
{{#if: {{#var: conf}}|==Configuration==
 
{{#if: {{#var: conf}}|==Configuration==
 
See the [[{{PAGENAME}}_Configuration]] page for {{#var: app}} configuration details.|}}
 
See the [[{{PAGENAME}}_Configuration]] page for {{#var: app}} configuration details.|}}
Line 72: Line 80:
 
{{#if: {{#var: installation}}|==Installation==
 
{{#if: {{#var: installation}}|==Installation==
 
See the [[{{PAGENAME}}_Install]] page for {{#var: app}} installation notes.|}}
 
See the [[{{PAGENAME}}_Install]] page for {{#var: app}} installation notes.|}}
 +
__NOTOC__

Latest revision as of 19:42, 3 February 2023

Description

python website  

Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. Python version 3 is the current implementation of Python while python2 is a legacy version no longer supported after 2020-01-01.

Environment Modules

Run module spider python to find out what environment modules are available for this application.

System Variables

  • HPC_PYTHON_DIR - installation directory
  • HPC_PYTHON_BIN - executable directory
  • HPC_PYTHON_LIB - library directory

and modifies PYTHONPATH and PYTHONHOME, so you could use them in your scripts.

Additional Information

  • After the appropriate environment module is loaded - type "python" at the command line to open an interactive session.
  • To run a python script type python scriptname.py. If the correct "shebang" line is used at the top of the script E.g.
#!/usr/bin/env python

then the script can be run directly as scriptname.py if it's in the executable path or as ./scriptname.py if it's in the current directory. The same rules apply to using a python script in a batch job script.

You can request installation of additional modules by submitting a request ticket in the Support System. The support request tickets can be used for requesting software installation, finding a solution to a particular problem, or just asking a question.

See also: Managing Python environments and Jupyter kernels

Matplotlib backend

If you are trying to use matplotlib and get an error similar to either of the following:

  • ImportError: No module named _tkinter
  • This application failed to start because no Qt platform plugin could be initialized.

then you should try the following before importing pyplot from matplotlib:

import matplotlib
matplotlib.use('Agg')

Output Buffering

If your job starts, but doesn't appear to produce output from 'print' statements in the job log for a long time, but you want to see that output immediately then turn off output buffering. You can either add a flush=True argument to the print calls you are interested in or run the script with

srun --unbuffered python SCRIPT.py

Available modules

  • To see all installed modules names load the environment module and run pip list or python -c "help('modules')" command before submitting a request for a new module installation.
  • To install their own packages, users can load any module that has python within and run pip install "package".
  • Users can define an install path by running: pip install --install-option="--prefix=/some/path/" package_name.

Below is a list of modules and versions installed in the default python version.

Expand this section to view list of available modules.

Automatically generated list of python modules installed with the Python Package Manager (pip) under the default python version. File PYTHON_MODULES is missing.

Name Version