Pip: Struggling with "setuptools must be installed to install from a source distribution"

Created on 25 Jun 2015  路  14Comments  路  Source: pypa/pip

I create a virtualenv using the latest release (13.0.3), but then I cannot install this package from source using pip: https://pypi.python.org/pypi/kevinarpe-rambutan3/1.7.1

I get the dreaded "setuptools must be installed to install from a source distribution". I've googled high and low on this issue and I am clueless. I saw some bug reports in this project, but none of the tips / solutions worked for me.

I tired upgrading setuptools in the virtualenv to latest, but still no luck. I also tried upgrading pip, but my virtualenv already has the latest.

I am a Python3.4.3 user on Linux.

Any ideas?

Apologies if this issue seems vague. I am truly baffled. I can provide more debug info if you need it.

auto-locked

Most helpful comment

I found the above recreating a virtualenv to not work. However I destroyed my virtualenv, and then upgraded pip and virtualenv and this issue resolved itself.

pip install -U virtualenv
pip install -U pip

All 14 comments

This is related to "import setuptools" from pip/req/req_install.py (~line 334). I tried manually on the python3 in my virtualenv. Due to bad linking (my fault) when building my python3 binary, the _ctypes module did not build correctly. As a result, setuptools cannot be imported. What a crazy red herring. Clearly not the fault of pip!

However, is it possible to provide the reason from ImportError in the InstallationError exception raised? It may be helpful in the future.

A colleague just got bitten by this one and the setuptools must be installed to install from a source distribution error message did not help.

The traceback when running import setuptools was:

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/user/dev/venvs/some_venv/lib/python3.4/site-packages/setuptools/__init__.py", line 12, in <module>
   from setuptools.extension import Extension
 File "/home/user/dev/venvs/some_venv/lib/python3.4/site-packages/setuptools/extension.py", line 8, in <module>
   from .dist import _get_unpatched
 File "/home/user/dev/venvs/some_venv/lib/python3.4/site-packages/setuptools/dist.py", line 18, in <module>
   from setuptools import windows_support
 File "/home/user/dev/venvs/some_venv/lib/python3.4/site-packages/setuptools/windows_support.py", line 2, in <module>
   import ctypes
 File "/usr/lib/python3.4/ctypes/__init__.py", line 7, in <module>
   from _ctypes import Union, Structure, Array
ImportError: /home/user/dev/venvs/some_venv/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add

As @kevinarpe suggested, I think we should improve the error message and include the exception.

@xavfernandez, I am also getting same error while trying to install from a source distribution.
What is the fix/workaround for this?
My pip list shows setuptools (18.4).
I am using virtualenvwrapper (4.6.0) and Python 3.4.0

I just got bitten by the exact same thing, probably due to a bug over at travis, cf. https://travis-ci.org/nschloe/matplotlib2tikz/builds/87418012.

From my understanding of the venv/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add issue, this happened after a minor upgrade of the distribution provide python 3.4.
Your venv contains symlinks to the standard library located in /usr/lib/python3.4 but a copy of the interpreter.

During the python upgrade, the symlinked standard library was updated but not the copied interpreter, making them incompatibles. A possible solution is to replace your venv python (located in path/to/your/venv/bin/python3.4) by the one from your system (/usr/bin/python3.4), a simple cp /usr/bin/python3.4 path/to/your/venv/bin/python3.4 should do it.

An other, even simpler, solution is to destroy and recreate your venv from scratch :)

@xavfernandez, destroy and recreate venv solved the issue.
Thanks for solution :)

Same issue here, not using venv but the good old virtualenv. Trying to fix it now...

The @xavfernandez solution worked for me as well. Thanks!

That solution worked for me as well! Not using venv, but virtualenv. Thanks!

Thanks for the tip. Copying the updated python interpeter to the virtualenv worked perfectly. Quite scary that this happened though...

I think this question happened because the setuptools version is not the newest , Just try update your setuptools into v20.3.6 or newer . I also found this question happened in Linux ,maybe because the default python in Linux setuptools version is 18.X

In this case try "pip install setuptools"

I found the above recreating a virtualenv to not work. However I destroyed my virtualenv, and then upgraded pip and virtualenv and this issue resolved itself.

pip install -U virtualenv
pip install -U pip

Thanks! hahnicity solution fixed it! :)

Was this page helpful?
0 / 5 - 0 ratings