Python: Difference between revisions

From UMIACS
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Python is a widely used general-purpose, high-level programming language.
[https://www.python.org/ Python] is a widely used general-purpose, high-level programming language.


== Python Versions ==
Most modern *NIX distributions ship with a system version of Python.  If the system version is not sufficient, there are multiple versions of Python available via [[Modules | GNU Modules]].  If you find that you need a version of Python that is not currently available through GNU Modules, you can always build it from [https://www.python.org/downloads/  source].


== Python Versions ==
If you are using Windows, you can install your required version of Python without Administrator credentialsPlease see the [[WindowsPython | Windows Python page]].
Most modern *NIX systems ship with a default version of Python.  If the default version is not sufficient, there are multiple version of Python are available via [[Modules | GNU Modules]].  If you find that you need a version of Python that is not currently available through GNU Modules, you can always build it from [https://www.python.org/downloads/  source].


== Python Environment ==
== Python Environment ==
Python utilizes a variable called 'PYTHONPATH', which is similar to the PATH variable used in many shells.  The PYTHONPATH variable tells they Python interpreter where to look to find modules.
Python utilizes a variable called 'PYTHONPATH', which is similar to the PATH variable used in many shells.  The PYTHONPATH variable tells the Python interpreter where to look to find modules.
To View your python path:
To view your python path:
<pre>bash:~$ python -c 'import sys; print sys.path'</pre>
<pre>bash:~$ python -c 'import sys; print sys.path'</pre>
You can add directories to your PYTHONPATH either through your shell, or in your Python code itself:
You can add directories to your PYTHONPATH either through your shell, or in your Python code itself:
Line 22: Line 23:


===== 'User' scheme=====
===== 'User' scheme=====
The user scheme allows a suer to install the module into the site userbase (<code>python -c 'import site; print site.USER_BASE'</code>).  This file location is included in the PYTHONPATH by default.
The user scheme allows a user to install the module into the site ''userbase'' (<code>python -c 'import site; print site.USER_BASE'</code>).  This file location is included in the PYTHONPATH by default.
<pre>bash:~$ python setup.py install --user</pre>
<pre>bash:~$ python setup.py install --user</pre>


====='Prefix' scheme=====
====='Prefix' scheme=====
The prefix scheme allows a user to install a module into a location of their choice.  '''Please note:''' This location will need to be added to the PYTHONPATH in order for the module to be found by python.
The prefix scheme allows a user to install a module into a location of their choice.  '''Please note:''' This location will need to be added to the PYTHONPATH in order for the module to be found by the Python interpreter.  
<pre>bash:~$ python setup.py install --prefix="/path/to/location"</pre>
<pre>bash:~$ python setup.py install --prefix="/path/to/location"</pre>


=====[[PythonVirtualEnv | Python Virtual Environment]]=====
=====[[PythonVirtualEnv | Python Virtual Environment]]=====
A Python Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.  For more information on setting up a virtualenv, please see the [[PythonVirtualEnv| Python Virtual Environment]] page.
A Python Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.  For more information on setting up a virtualenv, please see the [[PythonVirtualEnv| Python Virtual Environment]] page.
==== Windows Alternate Module Installation:====
 
==== Windows Alternate Module Installation====


=====Prefix Scheme=====
=====Prefix Scheme=====
Python on windows has a simpler layout, and as such the prefix scheme has traditionally been used to install additional packages intoa  separate location.
Python on Windows has a simpler layout, and as such the prefix scheme has traditionally been used to install additional packages into a separate location.
<pre>python setup.py install --prefix="\Temp\Python"</pre>
<pre>python setup.py install --prefix="\Temp\Python"</pre>

Latest revision as of 16:51, 20 October 2022

Python is a widely used general-purpose, high-level programming language.

Python Versions

Most modern *NIX distributions ship with a system version of Python. If the system version is not sufficient, there are multiple versions of Python available via GNU Modules. If you find that you need a version of Python that is not currently available through GNU Modules, you can always build it from source.

If you are using Windows, you can install your required version of Python without Administrator credentials. Please see the Windows Python page.

Python Environment

Python utilizes a variable called 'PYTHONPATH', which is similar to the PATH variable used in many shells. The PYTHONPATH variable tells the Python interpreter where to look to find modules. To view your python path:

bash:~$ python -c 'import sys; print sys.path'

You can add directories to your PYTHONPATH either through your shell, or in your Python code itself:

bash:~$ PYTHONPATH=$PYTHONPATH:/location/to/directory

                 ...or...

>>> sys.path.append('/location/to/directory')

Installing Modules

While some of the Versions of Python available in GNU modules provide a default set of modules pre-installed, you may wish to install your own. Typically you will not have access to the global Python install location, so you will have to install modules using an alternative method.

Unix/Linux Alternate Module Installation

'User' scheme

The user scheme allows a user to install the module into the site userbase (python -c 'import site; print site.USER_BASE'). This file location is included in the PYTHONPATH by default.

bash:~$ python setup.py install --user
'Prefix' scheme

The prefix scheme allows a user to install a module into a location of their choice. Please note: This location will need to be added to the PYTHONPATH in order for the module to be found by the Python interpreter.

bash:~$ python setup.py install --prefix="/path/to/location"
Python Virtual Environment

A Python Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. For more information on setting up a virtualenv, please see the Python Virtual Environment page.

Windows Alternate Module Installation

Prefix Scheme

Python on Windows has a simpler layout, and as such the prefix scheme has traditionally been used to install additional packages into a separate location.

python setup.py install --prefix="\Temp\Python"