Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip giving "ImportError: No module named setuptools" but I can import setuptools in python interpreter

I'm getting setup on a new mac and I was humming along just fine, installing pip and a few packages. When suddenly, every pip command I'd try to run would throw

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/basecommand.py", line 107, in main
    status = self.run(options, args)
  File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/commands/install.py", line 248, in run
    import setuptools
ImportError: No module named setuptools

I figured I had accidentally deleted a directory or something, so I tried reinstalling setuptools, following the advice of other answers on this site. I downloaded the setuptools egg from here and ran it like a shell script. Got this output:

Processing setuptools-0.6c11-py2.7.egg
Removing /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
setuptools 0.6c11 is already the active version in easy-install.pth
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Installing easy_install-2.7 script to /Library/Frameworks/Python.framework/Versions/2.7/bin

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

Now, if I start an interactive python session, I can import setuptools without error, but pip (and other command line scripts) complain that it's not installed. Any ideas why Python seems to be finding it, but not other scripts?

If it helps, this is what's in sys.path:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
like image 481
Hartley Brody Avatar asked Sep 09 '12 00:09

Hartley Brody


People also ask

How do I import setuptools in Python?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

Is setuptools included in Python?

Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions.

Does pip depend on setuptools?

In Fedora, our pip package Recommends setuptools. Practically that means: Majority of users who install pip will get setuptools by default. Users can explicitly uninstall setuptools after installing pip or exclude setuptools when installing pip.


1 Answers

Your pip doesn't seem to be in agreement with your Python. Compare:

File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/basecommand.py", line 107, in main

to

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg

If python2.7 has setuptools, then you should have

/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7

available, in which case

easy_install-2.7 pip

should give you pip-2.7.

like image 70
DSM Avatar answered Nov 15 '22 11:11

DSM