Not possible to import modules correctly while running Python within a Pig script
search cancel

Not possible to import modules correctly while running Python within a Pig script

book

Article ID: 295121

calendar_today

Updated On:

Products

Services Suite

Issue/Introduction

This article discusses what to do when it is not possible to import modules correctly while running Python within a Pig script. 

When running a Python within a Pig script, the following error was seen:

  • The wrong version of Python may be reported, for example, Python version 2.7.10 installed but when "sys.version" is run in Python, a different version is displayed, such as "2.5.3".
  • Some modules may not import correctly:
ImportError: No module named json
Jython is being used with version 2.5.3 and does not contain the same number of modules as standard Python distributions.

Environment

Product Version: 3.0

Resolution

Review the Pig script and confirm that Jython is being used. For example, this line runs the Python script utils.py via Jython:

REGISTER './utils.py' using jython as utils; 
Review Jython documentation to add the required module into Jython.

Note: Upgrading to Jython 2.7 will likely help as extra modules are included, such as the JSON module from the example above.