TLDR - I want to run the command sudo yes | sudo pip3 uninstall numpy twice in EMR bootstrap actions but it runs only once.
I will first say that my goal is to run a Pyspark-enabled EMR managed notebook, running on an EMR cluster. For various reasons I need pandas to be installed on the cluster as well. First, I encountered a problem where two numpy versions exist in the default python3 installation, and they both have to be removed to use the newer version (as in this thread - How do I have multiple versions of numpy installed on Amazon EMR and how to I delete the early versions?).
If I ssh into the master node and perform sudo yes | sudo pip3 uninstall numpy twice, it works:
[hadoop@ip-xxx-xx-xx-xxx ~]$ sudo yes | sudo pip3 uninstall numpy
Uninstalling numpy-1.21.1:
/usr/bin/f2py
/usr/local/bin/f2py
/usr/local/bin/f2py3
/usr/local/bin/f2py3.7
.......
.......
.......
/usr/local/lib64/python3.7/site-packages/numpy/typing/tests/test_runtime.py
/usr/local/lib64/python3.7/site-packages/numpy/typing/tests/test_typing.py
/usr/local/lib64/python3.7/site-packages/numpy/version.py
Proceed (y/n)? Successfully uninstalled numpy-1.21.1
[hadoop@ip-xxx-xx-xx-xxx ~]$ sudo yes | sudo pip3 uninstall numpy
Uninstalling numpy-1.16.5:
/usr/local/lib64/python3.7/site-packages/numpy
/usr/local/lib64/python3.7/site-packages/numpy-1.16.5-py3.7.egg-info
Proceed (y/n)? Successfully uninstalled numpy-1.16.5
I get numpy removed from the python3 installation, and then I can install numpy and pandas normally.
The problem happens when I want to perform the same thing using bootstrap actions. Using this bootstrap.sh file:
#!/bin/bash
sudo yes | sudo yum install python3-devel
sudo pip3 install cython
sudo pip3 install matplotlib
sudo yes | sudo pip3 uninstall numpy
sudo pip3 install pyspark boto3
sudo yes | sudo pip3 uninstall numpy
sudo pip3 install numpy
sudo pip3 install pandas
Notice that I'm uninstalling numpy twice here, but it simply ignores the second sudo yes | sudo pip3 uninstall numpy command! Because I haven't uninstalled the second numpy installation it results in a broken pandas installation (again, see the thread I linked to previously). Why does this happen? Because the bootstrap actions don't work, and it's impossible to ssh into the slave nodes I'm left with a broken pandas installation and no way to fix it.