Question

I'm having great problems with getting the python site package httplib2 to work properly in IDLE. I'm using a mac with OSX 10.8.3 and python 2.7. I used the following installation steps to install httplib2 with macports:

1. $sudo port install py27-httplib2

I checked that it installed by using:

2. $port contents py27-httplib2

which returned a whole pile of files in the following directory (I'm just showing the first three):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg-info
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2/__init__.py
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2/__init__.pyc

Then I added the following lines to my .bash_profile file thus:

$echo "export PYTHONPATH=\"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2:$PYTHONPATH\"">>.bash_profile
$source .bash_profile

I checked that the paths had indeed been incorporated into the environment (but I also noticed that my PATH is messy):

$env
PATH=/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:
   /opt/local/sbin:/opt/local/bin:/opt/local/sbin:
   /Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:
   /usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/mysql/bin:
   /Users/lydia/programs/pagan/bin
PWD=/Users/lydia
LANG=en_AU.UTF-8
SHLVL=1
HOME=/Users/lydia
PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2:
   /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:

I then invoked python and ran 2 lines of code in the terminal window as shown below:

$python
>>> import sys
>>> import httplib2

If I run the same two lines of code in IDLE I get the following error:

>>> import httplib2
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import httplib2
 ImportError: No module named httplib2

My question is: What must I do to get IDLE to recognise that httplib2 is installed and has a valid path? As I need to get my code to work on various machines I can't hard-code the path to httplib2 in my code.

Thanks in advance!

Was it helpful?

Solution

1) You should never care what the python interpreter does. It is not the same as running a python program, and in my opinion it is useless. Instead, type your code into a file named my_prog.py, and run it:

$ python my_prog.py

2) You should never care what IDLE does because it is the worst text editor imaginable. Your mac comes with vim, which you can learn how to use by doing:

$ vimtutor

Once you've learned the basics, you can upgrade and install macvim, and something like the vivid chalk color scheme, for a real sharp looking editor. There are also thousands of useful plugins you can employ with macvim. You can search google for the "best of the macvim plugins" and see which ones you might want.

3) Why do you use macports to install modules? You can download the module, then untar it:

.../Downloads$ tar xfvz some-name.tar.gz

then cd into the newly created directory:

.../Downloads$ cd some-name

then read the README or INSTALL file for the directions on how to install the module, however typically all you do is:

 .../Downloads/some-name$ sudo python setup.py install

That will install the python module in the default location, which is not /opt/local on my mac; it's:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

You shouldn't need macports for something so trivial.

4) It looks like other people have had problems with IDLE when installing modules in non-standard locations, so you might want to search google and see if you can find a solution there: e.g. http://ubuntuforums.org/showthread.php?t=253555

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top