0
votes

I am using Mac OSX 10.10.5, and Python version 3.5.2, and IDLE version 3.5.2.

I am extremely new to Python, and am trying to use the urllib3 module in IDLE. I have used the following code in the Terminal with success (the number 200 is returned):

import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'http://httpbin.org/robots.txt')
r.status

But the same code does not work in IDLE. In IDLE I get the following error:

Traceback (most recent call last):
  File "/Users/faculty/Documents/Python/Scraping_v1_d1.py", line 1, in <module>
    import urllib3
ImportError: No module named 'urllib3'

I have also attempted to use other code such as the following in IDLE:

import urllib3
htmlfile = urllib3.urlopen("http://google.com")
htmltext = htmlfile.read()
print (htmltext)

But I get the same error.

In my site-packages folder I have these pip and urllib3 folders:

1) pip

2) pip-9.0.1.dist-info

3) urllib3

4) urllib3-1.19.dist-info

I found one source that suggested that I try to do the following:

import sys
sys.version
sys.path

This is the response in Terminal:

import sys sys.version '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]' sys.path ['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']

When I type the same code into IDLE, nothing happens (this is all I get):

========= RESTART: /Users/faculty/Documents/Python/Scraping_v1_d1.py =========

I have searched the web and stackoverflow.com extensively, but can't locate a solution. Does anyone have any insight?

Thanks!

1
Notice on the terminal, those are version 2.7 paths. OSX has version 2.7 and keeps it even if you also install 3.5.2. I suspect you are running python at the terminal. Try python3 and see what happens. urllib3 should still work there but hopefully you are getting closer to the problem.tdelaney
Looking at my linux mint, python-urllib3 is its own package. You may still need to install your own version. I prefer using platform versions (I have a debian linux and install with sudo apt-get install python-urllib3 but OSX will be different) over the latest python versions (sudo pip3 install urllib3) but I may be a radical that way!tdelaney
Someone has posted the correct answer. You should mark it as correct.user48956

1 Answers

1
votes

Like the error message already shows:

You have two Python Versions on your Mac. Python 3.5 and Python 2.7 (by default).

The IDLE process depends on the python version in which IDLE starts. So make sure your using the same Python version (same IDLE). The command "pip install urllib3" only works for the default python version - which is different to your python version in IDLE.

So you just have to install urllib3 for Python3.5 too.