Pivotal Knowledge Base

Follow

When running Python within a Pig script, cannot import modules correctly

Environment

Product Version
Pivotal HD  3.0.1
Pig script  0.14

Symptom

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 

Cause 

Jython is being used with version 2.5.3 and does not contain the same number of modules as standard Python distributions.

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 that upgrading to Jython 2.7 will likely help as extra modules are included such as the JSON module from the example above. 

 

 

Comments

Powered by Zendesk