I am currently trying to upgrade pip and then install paramiko inside a python script because the script itself makes use of paramiko. Below is a simple case of what I am trying to accomplish
import pip
try:
import paramiko
except ImportError:
pip.main(["install", "--upgrade", "pip"])
reload(pip)
pip.main(["install", "--user", "paramiko"])
import paramiko
ssh = paramiko.SSHClient()
I am running this script in an Ubuntu 16.04 VM with python 2.7 which doesn't have paramiko and pip version 8.1.1. For the output of the pip upgrade after running the script, I get:
Collecting pip Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 712kB/s Installing collected packages: pip Successfully installed pip-8.1.1 You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
After that, it tries to install paramiko as expected, but it fails because it basically can't install the Cryptography dependency that paramiko uses. However, if it was using the upgraded pip, this would not be a problem. I have reverted the VM back to a previous snapshot to manually install paramiko by doing
pip install --upgrade pip
pip install --user paramiko
in the shell and it works, but I need to be able to perform this in a script.
Note, I also reverted the VM to a previous snapshot and tried installing paramiko with the above command in the shell, but without performing the pip upgrade first, and as expected I get the same error as what the script gives when trying to install paramiko. Now I have done a bit of testing by trying to having this in the script:
pip.main(["install", "--upgrade", "pip"])
reload(pip)
pip.main(["install", "--upgrade", "pip"])
reload(pip)
and as for the output I get this:
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)100% |████████████████████████████████| 1.3MB 712kB/s Installing collected packages: pip Successfully installed pip-8.1.1 You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whlInstalling collected packages: pip Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Notice how it says using cached pip-9.0.1 at the second pip upgrade. Does this mean after the reload, the script is using pip 9.0.1? If so then why is the paramiko install not using the upgraded pip? How can I get the paramiko to use the upgraded pip?