Unable to use pip command in CDP

You may not be able to use the pip command in CDP releases 7.1.7 and above and may see the following error when using pip in a command: “ImportError: cannot import name chardet”.

To fix this issue and use the pip command, you must download pip from pypi.org and copy the chardet package to the target directory.

  1. SSH into the Hue host as a root user.
  2. Change to the following directory:
    cd /opt/cloudera/parcels/CDH/lib/hue
  3. Check the pip version by running the following command:
    ./build/env/bin/pip --version
  4. Download the pip package by running the following command:
    wget https://files.pythonhosted.org/packages/53/7f/55721ad0501a9076dbc354cc8c63ffc2d6f1ef360f49ad0fbcce19d68538/pip-20.3.4.tar.gz -O ~/pip-20.3.4.tar.gz
  5. Extract the tar file by running the following command:
    tar xvzf ~/pip-20.3.4.tar.gz -C ~
  6. Copy the chardet package to the target directory by running the following command:
    cp -R ~/pip-20.3.4/src/pip/_vendor/chardet build/env/lib/python2.7/site-packages/pip/_vendor/.
  7. Verify that you can run a pip command without any error by running any of the following sample commands:
    ./build/env/bin/pip freeze
    or
    ./build/env/bin/pip list