Python

Do you need to use a Python library you think may not be installed on RCE6? As an RCE user, you have the ability to install Python modules locally to your home directory and use them in your projects.

Before going ahead and installing that Python module you need, determine whether that module is already installed globally.

List installed Python Modules

1. Determine The Required Python Version: RCE6 supports Python 2.6, 2.7, and 3.3. You need to determine which version of Python you'd like to develop with. Remember, some Python modules are version specific.

2. Access the Console: If you know how to access the console in the RCE via NX or SSH, skip this step, otherwise, please read #HMDCBasics.

2. Search for the Python Module: Each version of Python installed on the RCE maintains its own module path. Determine whether a Python module is installed for a specific version of Python by using pip, Python's package management utility, to list packages installed for a desired version.

Python 2.6

pip list | grep $MODULE

Example:

$ pip list | grep simplejson
simplejson (2.0.9)

Python 2.7

pip27 list | grep $MODULE

Example:

$ pip27 list | grep simplejson
$

Python 3.3

pip33 list | grep $MODULE

Example:

$ pip33 list | grep simplejson
$

 

3. Success? If your module is installed for the Python version you need, stop right there. You're done. In the examples above, a user determines that the module simplejson is only installed for Python 2.6.

Installing a Python Module

1. Install the Module: If the module is not installed or installed for the wrong version of Python, install the module locally to your home directory. You can install the module for multiple versions of Python if your project requires cross-compatibility.

Python 2.6

pip install $MODULE --user

Example:

$ pip install simplejson --user

Python 2.7

pip27 install $MODULE --user

Example:

$ pip27 install simplejson --user

Python 3.3

pip33 install $MODULE --user

Example:

$ pip33 install simplejson --user

 

Troubleshooting

1. Can't Find Your Module? If you're unable to locate your module using pip, maybe you're searching for the wrong module name. If you've decided you needed to install a module because, for example, import simplejson, did not work from a Python interactive console, you may have the wrong name. Often Python class names differ from Python module names. Try using the pip search feature. When searching the Python module repository using pip, try using a more generic derivative of the module name. Search for json, instead of simplejson.

Python 2.6

pip search $MODULE

Example:

$ pip search json

Python 2.7

pip27 search $MODULE

Example:

$ pip27 search json

Python 3.3

pip33 search $MODULE

Example:

$ pip33 search json

 

2. Still No Dice? Try searching the PyPI repository, the official Python module repository. Use google. Very rarely, some modules require that you manually compile Python packages using setup.py. Pylucene is a popular Python module which provides a Python interface to Lucene which is not in the PyPi repository.