Loanb222 Loanb222 - 3 months ago 46
Python Question

How can I use urllib.request.urlretrieve with python 2.7

I am trying to get images dowloaded from image-net.org so that I can create a haar cascade classifier. I am following this tutorial https://www.youtube.com/watch?v=z_6fPS5tDNU&list=PLQVvvaa0QuDdttJXlLtAJxJetJcqmqlQq&index=18 but I am using python 2.7 instead of python 3. So in the tutorial he has the line:

urllib.request.urlretrieve(img, pathToImage)


Instead of
import urllib.request
I did this
import urllib2
So I tried this but it isn't vaild

urllib2.urlretrieve(i, "Negatives/"+str(num)+".jpg")


Thank you in Advance!

Answer

You just need to import urllib without '2'

import urllib
urllib.urlretrieve(i, "Negatives/"+str(num)+".jpg")