Pivotal Knowledge Base


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


Product Version
Pivotal HD  3.0.1
Pig script  0.14


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.


  • 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. 




Powered by Zendesk