9
votes

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.

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
@birryree my build-essential is the latest version and gcc gives me /usr/bin/gcc also latest when i tried to upgrade it. - Jaffar
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
@birryree thank you! i just installed python-dev, for some reason it was not installed. please submit an answer so i can accept it! - Jaffar
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

2 Answers

21
votes

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.

9
votes

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.