3

Edit: Before you start deleting/modifying installs, please glance over StvnW's answer/summary to make sure you are applying the solution that is appropriate for you.

I've installed python 2.7.5 and pip [edit: mac OSX Mountain Lion.] I've run "pip install praw" in terminal. All good. When I run python and run "import praw" I get:

    ...$ python
    Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import praw
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named praw

...same ImportError from a script.

when I install praw I get this:

    $ pip install praw
    Downloading/unpacking praw
      Downloading praw-2.1.10.tar.gz (83kB): 83kB downloaded
      Running setup.py egg_info for package praw

    Requirement already satisfied (use --upgrade to upgrade): requests>=1.2.0 in
    /usr/local/lib/python2.7/site-packages (from praw)
    Requirement already satisfied (use --upgrade to upgrade): six in
    /usr/local/lib/python2.7/site-packages (from praw)
    Requirement already satisfied (use --upgrade to upgrade): update-checker>=0.6 in
    /usr/local/lib/python2.7/site-packages (from praw)
    Requirement already satisfied (use --upgrade to upgrade): setuptools in
    /usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from update-
    checker>=0.6->praw)
    Installing collected packages: praw
      Running setup.py install for praw

        Installing praw-multiprocess script to /usr/local/bin
    Successfully installed praw
    Cleaning up...

In python if I run help('modules') it isn't there.

Relatively new to python and I haven't been able to sort this out with google search. Any hints would be much appreciated.

Edit:

SitRep:

I've uninstalled 2.7.2, uninstalled praw, and uninstalled (homebrew) pip. I ran python 2.7.5 and it couldn't find the module (as you would suspect.) I then reinstalled pip with easy_install and now 2.7.5 is finding praw but giving this error:

    $ python
    Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import praw
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in <module>
         from update_checker import update_check
       File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in <module>
         from pkg_resources import parse_version as V
    ImportError: No module named pkg_resources
    >>>

Thanks for the help so far, the spurious install was the root of problem 1.

The solution to the final problem can be found here:

No module named pkg_resources

I wish there were some way to summarize this for future readers, but I've done so many things that I no longer recall what addressed what. I basically uninstalled everything (python 2.7.2, 2.7.5, praw, pip,) reinstalled 2.7.5 from http://python.org/download/, reinstalled pip with easy_install (and sudo command) instead of homebrew, reinstalled praw with sudo command, and followed the directions for the subsequent module error in the link above. Hope that helps. :)

Community
  • 1
  • 1
Dean Solecki
  • 133
  • 1
  • 1
  • 8
  • wierd. If it is windows, just exit and repeat it again (dont know if that would fix the issue though) – karthikr Oct 16 '13 at 23:29
  • How did you install pip? If you `import sys; print sys.path` is /usr/local/python2.7/site-packages/ included? – Wooble Oct 16 '13 at 23:31
  • Not quite: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages' Edit:These are the only references to site-packages. – Dean Solecki Oct 16 '13 at 23:34

3 Answers3

4

The OS X system versions of Python live in /System/Library/Frameworks/Python.Framework/<verson>, each of which links to /Library/Python/<version>/site-packages. Seems like you have installed another version of python and/or pip to /usr/local, but when you invoke python you are still getting the system version.

Try this:

$ /usr/local/bin/python
>>> import praw

I'd also recommend looking into tools like pyenv and virtualenv if you are going to do any amount of work with Python. Pyenv lets you easily manage and switch between multiple versions (including micro versions x.x.3, x.x.5, etc). Virtualenv lets you create isolated Python environments where you can pin down versions of site-packages specific to a particular project.

Edit (summarizing):

  • sudo easy_install pip will install pip under /System/Library/Python/<version>. Calling that pip will install packages to /Library/Python/<version>/site-packages
  • brew install python will install a second version of python — including pip — under /usr/local/. That pip will put packages in /usr/local/lib/python<version>/site-packages/`.
  • One version may not see packages installed to the other.
  • which python and which pip are helpful for troubleshooting.
  • Dean's final solution above results in user packages being installed to the system site-packages.
  • Despite Dean's choice to update the system Python, many would advocate instead using brew, pyenv, and virtualenv to isolate oneself from the system Python.
StvnW
  • 1,630
  • 12
  • 16
  • $ /usr/local/bin/python Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import praw Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in from update_checker import update_check File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in from pkg_resources import parse_version as V ImportError: No module named pkg_resources >>> – Dean Solecki Oct 17 '13 at 00:28
  • Oh... it didn't respect the formatting. That was what it spit out. I reinstalled praw with easy_install and pip (and reinstalled pip with easy_install and homebrew) and I am getting different errors depending on which route I take. That is kind of like progress. ;) – Dean Solecki Oct 17 '13 at 00:31
  • 1
    `sudo easy_install pip` will install pip under /Library/Python/, whereas `brew install python` will install python and pip under /usr/local. `ImportError: No module named pkg_resources` is because you are missing `setuptools`. You'll need to `pip install setuptools`. – StvnW Oct 17 '13 at 01:04
  • StvnW basically summarized the issue. mixing pip and brew messed up locations, but easy_install and pip played nice. The python download from http://python.org/download/ replaced the default install seamlessly. – Dean Solecki Oct 17 '13 at 01:13
  • I would recommend taking the other path, leaving the system install alone and dealing instead exclusively with [pyenv](https://github.com/yyuu/pyenv) and [virtualenv](https://pypi.python.org/pypi/virtualenv). – StvnW Oct 17 '13 at 02:36
1

It's strange. I am suspecting you have another version of python2.7 on your mac os

demo.b
  • 2,979
  • 1
  • 26
  • 26
0

If you are using a mac. Check the version of python on your shell's path using which python. Then make sure that the shebang line in the script you are trying to run uses the same version of python.

In my terminal I typed which python and got the output /usr/local/bin/python

I went to the script I was trying to run and added the following to the first line #!/usr/local/bin/python

Then I went back to my terminal. Checked that I was in the same directory as the script I wanted to run and typed ./my_script.py

If you don't see any output at this point make sure that you have execution permission enabled for your script by typing chmod +x my_script.py in ther terminal. Then try running the script again using ./my_script.py

Luke Murray
  • 851
  • 8
  • 10