2

I installed oauth2 by just downloading tar.gz package and doing python setup.py install. However I'm getting this error

bash-3.2$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named oauth2
>>>

The path to oauth2 is in PYTHONPATH (so that shouldn't be the issue) as I added this line to ~/.bashrc:

PYTHOHPATH=$PYTHONPATH:/Users/me/Downloads/oauth2-1.5.211/

However, when I do this:

bash-3.2$ cd /System/Library/Frameworks/Python.framework/Versions/2.7/
bash-3.2$ ls
Extras      Headers     Mac     Python      Resources   _CodeSignature  bin     include     lib
bash-3.2$ Python
Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13) 
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth2
>>> 

it works just fine. Any idea how I should install oauth2 to avoid ImportError from python?

P/S: this is the simlink for python command

python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Arman
  • 1,074
  • 3
  • 20
  • 40
  • You shouldn't need to modify the `PYTHONPATH` if you've installed the package. (Also, you misspelled it, but that may just be a C&P error). – Julian Jul 24 '12 at 21:32
  • Have you been able to install any other package with `python setup.py install`? – Lenna Jul 24 '12 at 21:35

2 Answers2

1

I don't have an answer, but I have some general suggestions:

Run python setup.py install with the same python that you intend to use it from (in your case one is capitalised, the other is not).

I always export my bashrc variables to ensure they are global, but I am not sure that is your issue here.

When running scripts in the pwd, always run them with ./. In your case run python as ./Python to have confidence that you are running the executable you think you are running.

Check your spelling of PYTHONPATH. If you think you have it right, do import sys; print('\n'.join(sys.path)) from within your python session and ensure that the appropriate directory is there

pelson
  • 21,252
  • 4
  • 92
  • 99
  • Looks like I misspelled PYTHONPATH. However, now I get 'ImportError: No module named httplib2' when importing httplib2. I installed httplib2 by downloading the package and doing 'sudo python setup.py install' (lower-case python), included it PYTHONPATH (PYTHONPATH=$PYTHONPATH:/Users/armansu/Downloads/httplib2-0.7.4/). No luck. Any ideas? – Arman Jul 24 '12 at 23:47
  • Was it the appropriate directory there when you printed the sys.path? I don't tend to get these issues when I use the same python executable for both install and run. – pelson Jul 25 '12 at 06:37
  • Instead of managing your PYTHONPATH, are you aware of .pth files? They are just text files with the path to include for module resolution, you can find where to put them with `pelson@~> python -c "import site; print site.getusersitepackages()" /Users/pelson/Library/Python/2.7/lib/python/site-packages` (see http://stackoverflow.com/questions/700375/how-to-add-a-python-import-path-using-a-pth-file) – pelson Jul 25 '12 at 06:41
0

it looks like you have two different versions of python installed, and one of them you launched using Python as opposed to python.

Since your second example workd, it looks like you've installed oauth2 using Python.

ernie
  • 6,356
  • 23
  • 28