11

I'm trying to install the python-Levenshtein library on linux, but whenever I try to install it via:

sudo pip install python-Levenshtein

I get this error:

Command "/usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-LAmG4b/python-Levenshtein/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-KGiQPH-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-LAmG4b/python-Levenshtein

And the error code: error: command 'gcc' failed with exit status 1

I'm using debian linux.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
Jaf
  • 135
  • 1
  • 1
  • 9
  • 2
    Most likely, you don't have `gcc` or the build tools installed. Verify this by typing `which gcc` in your terminal. Can you try again after executing `sudo apt-get install build-essential`? – wkl Sep 15 '15 at 20:34
  • @birryree my build-essential is the latest version and gcc gives me /usr/bin/gcc also latest when i tried to upgrade it. – Jaf Sep 15 '15 at 20:39
  • 1
    Hm, in that case, before you resort to more serious debugging methods - do you have `libpython-dev` installed? That package is also needed to build a lot of Python modules that bind with C or expose C extensions. – wkl Sep 15 '15 at 20:45
  • @birryree thank you! i just installed python-dev, for some reason it was not installed. please submit an answer so i can accept it! – Jaf Sep 15 '15 at 20:49
  • Have you tried reading /tmp/pip-build-LAmG4b/python-Levenshtein to see what the error is? This might well point at libpython-dev being missing. – W. H. Bell Sep 15 '15 at 20:50

3 Answers3

28

One of the python-Levenshtein maintainers here.

Make sure you have python-dev and build-essential packages.

Are you sure that's full error message as the actual error seem to be missing?

If a log file is created can you peek into it and add its content to the question.

Also read the official Python package installation guide. Use virtual environments. Never do sudo pip install unless you have a specific reason to do so.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • 1
    You brought me on the right track - I was missing `libpython3-dev`. Modern times... – Jule Nov 20 '19 at 10:59
  • Could you add some more guidance on how to install both? I believe python-dev can be installed in macOS by brew reinstall python3.x, but how can I install build-essential? – halo09876 Jul 14 '20 at 22:55
  • These instructions apply to Ubuntu Linux from 2015. if you have an issue please open a new question and describe your setup and problem in detail. – Mikko Ohtamaa Jul 15 '20 at 07:56
13

Just in case if anyone will encounter the same issue as the author of this question:

I faced the same issue on Ubuntu 20.04. I wanted to use a library which depends on python-Levenstein.

Mikkos answer above was correct. When installing, I have obtained further line in the end of exception: 'x86_64-linux-gnu-gcc' failed with exit status 1 which directly means a problem with building tool.

Then I found this answer by Paulie

Overall, in my case it was simply executing: sudo apt-get install python3.7-dev

Then I installed the library using:

pip install python-Levenshtein

I hope this will be clear for everyone.

Aidos
  • 729
  • 7
  • 20
0

I had a similar error when installing python-Levenshtein and I was able to install it like this:

pip install conda
conda install -c conda-forge python-levenshtein
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257