python download code example

Example 1: python download image

import urllib.request

image_url = 'https://bit.ly/2XuVzB4' #the image on the web
save_name = 'my_image.jpg' #local name to be saved
urllib.request.urlretrieve(image_url, save_name)

Example 2: how to install python libraries

python -m pip install SomePackage

Example 3: how to install modules in python

# In cmd.exe type:     
pip install #module_name

Example 4: pip install python 3

You cannot just pip install python3 because it is not a library.

If you want to install the latest python3:
https://www.python.org/ftp/python/3.8.2/python-3.8.2.exe

Example 5: python3 download file

import urllib.request

print('Beginning file download with urllib2...')

url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg'
urllib.request.urlretrieve(url, '/Users/scott/Downloads/cat.jpg')

Example 6: latest version of python

# For macs... 
#  Apparently you don't want to upgrade 2.* just install 3.*

% brew install python3