83

I just updated Python to 2.6.4 on my Mac. I installed from the dmg package.

The binary did not seem to correctly set my Python path, so I added '/usr/local/lib/python2.6/site-packages' in .bash_profile

>>> pprint.pprint(sys.path)  
['',
'/Users/Bryan/work/django-trunk', 
'/usr/local/lib/python2.6/site-packages',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',  
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages']

Apparently that is not all the required paths because I can't run iPython.

$ ipython  
Traceback (most recent call last):  
  File "/usr/local/bin/ipython", line 5, in <module>  
  from pkg_resources import load_entry_point  
ImportError: No module named `pkg_resources`

I've done Google searches and I can't really figure out how to install pkg_resources or make sure it's on the path.

What do I need to do to fix this?

Pierre GM
  • 19,809
  • 3
  • 56
  • 67
BryanWheelock
  • 12,146
  • 18
  • 64
  • 109

10 Answers10

76

I encountered the same ImportError. Somehow the setuptools package had been deleted in my Python environment.

To fix the issue, run the setup script for setuptools:

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python

If you have any version of distribute, or any setuptools below 0.6, you will have to uninstall it first.*

See Installation Instructions for further details.


* If you already have a working distribute, upgrading it to the "compatibility wrapper" that switches you over to setuptools is easier. But if things are already broken, don't try that.

cwc
  • 8,687
  • 2
  • 20
  • 19
  • 3
    This is the right way to do it. Without pkg_resources, `easy_install` will likely also not work (so `easy_install` and `pip` won't be able to install setuptools). – Alex Churchill Aug 15 '12 at 20:57
  • Installing Distribute or setuptools is, in fact, what the accepted answer recommended. I've updated the original answer a bit to make it more obvious. BTW, it is somewhat dangerous to download and install something from an insecure URL like that without examining the contents of the file first. – Ned Deily Apr 20 '13 at 17:35
74

[UPDATE] TL;DR pkg_resources is provided by either Distribute or setuptools.

[UPDATE 2] As announced at PyCon 2013, the Distribute and setuptools projects have re-merged. Distribute is now deprecated and you should just use the new current setuptools. Try this:

curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py

Or, better, use a current pip as the high level interface and which will use setuptools under the covers.

[Longer answer for OP's specific problem]:

You don't say in your question but I'm assuming you upgraded from the Apple-supplied Python (2.5 on 10.5 or 2.6.1 on 10.6) or that you upgraded from a python.org Python 2.5. In any of those cases, the important point is that each Python instance has its own library, including its own site-packages library, which is where additional packages are installed. (And none of them use /usr/local/lib by default, by the way.) That means you'll need to install those additional packages you need for your new python 2.6. The easiest way to do this is to first ensure that the new python2.6 appears first on your search $PATH (that is, typing python2.6 invokes it as expected); the python2.6 installer should have modified your .bash_profile to put its framework bin directory at the front of $PATH. Then install easy_install using setuptools following the instructions there. The pkg_resources module is also automatically installed by this step.

Then use the newly-installed version of easy_install (or pip) to install ipython.

easy_install ipython

or

pip install ipython

It should automatically get installed to the correct site-packages location for that python instance and you should be good to go.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • I messed up when I tried to install setuptools last night. I neglected to finish the installation by running the .egg file as if it were a shell file. $ sh setuptools-0.6c11-py2.6.egg I guess that added the new Python path somewhere. – BryanWheelock Nov 18 '09 at 19:30
  • NOTE: The actual answer that resolved this issue for me was below- see http://stackoverflow.com/a/10538341/293064 – Jay Taylor Apr 20 '13 at 16:45
  • I've updated this old answer a bit to make it more obvious that the solution is to either install `Distribute` or `setuptools`. The specific steps were in the links. The OP's question covered other items. – Ned Deily Apr 20 '13 at 17:22
  • A further edit to reflect the deprecation of `distribute` in favor of the new `setuptools` and to mention `pip`. – Ned Deily Sep 03 '13 at 06:23
  • 1
    getting ```python ez_setup.py File "ez_setup.py", line 1 ^ SyntaxError: invalid syntax``` :( – hi15 May 01 '17 at 08:08
7

In case of upgrading your python on mac os 10.7 and pkg_resources doesn't work, the simplest way to fix this is just reinstall setuptools as Ned mentioned above.

sudo pip install setuptools --upgrade
or sudo easy_install install setuptools --upgrade
vutran
  • 2,145
  • 21
  • 34
3

On my system (OSX 10.6) that package is at

/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py

I hope that helps you figure out if it's missing or just not on your path.

Bryan McLemore
  • 6,438
  • 1
  • 26
  • 30
1

The reason might be because the IPython module is not in your PYTHONPATH.

If you donwload IPython and then do python setup.py install

The setup doesn't add the module IPython to your python path. You might want to add it to your PYTHONPATH manually. It should work after you do :

export PYTHONPATH=/pathtoIPython:$PYTHONPATH

Add this line in your .bashrc or .profile to make it permanent.

Ben
  • 11
  • 1
0

I realize this is not related to OSX, but on an embedded system (Beagle Bone Angstrom) I had the exact same error message. Installing the following ipk packages solved it.

opkg install python-setuptools
opkg install python-pip
Mark Lakata
  • 19,989
  • 5
  • 106
  • 123
0

I got this error on Ubuntu, and the following worked for me:

Removed the dropbox binaries and download them again, by running:

sudo rm -rf /var/lib/dropbox/.dropbox-dist
dropbox start -i
igr
  • 4,529
  • 2
  • 15
  • 20
0

I encountered with the same problem when i am working on autobahn related project.

1) So I download the setuptools.-0.9.8.tar.gz form https://pypi.python.org/packages/source/s/setuptools/ and extract it.

2 )Then i get the pkg_resources module and copy it to the folder where it needed. **in my case that folder was C:\Python27\Lib\site-packages\autobahn

Nithila
  • 139
  • 1
  • 9
0

In my case, package python-pygments was missed. You can fix it by command:

sudo apt-get install python-pygments

If there is problem with pandoc. You should install pandoc and pandoc-citeproc.

sudo apt-get install pandoc pandoc-citeproc

kha
  • 349
  • 3
  • 18
0

Try this only if you are ok with uninstalling python.

I uninstalled python using

brew uninstall python

then later installed using

brew install python

then it worked!

Bharath Pabba
  • 1,725
  • 5
  • 16
  • 24