17

I installed Python 2.7.15rci and Python 3.6.7 on Ubuntu. When i did 'pip list' on virtualenv it returns me:

Django (2.1.5)
pip (9.0.1)
pkg-resources (0.0.0)
pytz (2018.9)
setuptools (39.0.1)
wheel (0.32.3)

I'm trying to install mysqlclient (pip install mysqlclient) and returns an error.

  unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient:
    /usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
    creating build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/MySQLdb
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,1,'final',0) -D__version__=1.4.1 -I/usr/include/mysql -I/home/david/env/project/include -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.6/MySQLdb/_mysql.o
    unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-build-pq18uxjj/mysqlclient/

So, I have tried different methods found like:

sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libmysqlclient-dev

and some more... but none of them work for me and the problem persists. Any suggestions?

Thank you!

MAss
  • 175
  • 1
  • 1
  • 11
  • you need to install `default-libmysqlclient-dev` according to the docs, not `libmysqlclient-dev`. – dirkgroten Jan 24 '19 at 16:33
  • 1
    I installed `default-libmysqlclient-dev` too but it still does not work ... – MAss Jan 24 '19 at 16:47
  • You say you've tried `sudo apt-get install python-dev python3-dev`, are those still installed? Or did you uninstall each time? All of these need to be installed. – dirkgroten Jan 24 '19 at 16:50
  • Yes, they are still installed python-dev (2.7.15~rc1-1) python3-dev (3.6.7-1~18.04) default-libmysqlclient-dev (1.0.4) libmysqlclient-dev (8.0.14-1ubuntu18.04) – MAss Jan 24 '19 at 16:52
  • you're using python3, so only one that matters is python3-dev. Try also installing `gcc` (`sudo apt-get install gcc`). – dirkgroten Jan 24 '19 at 16:55
  • the problem persists :( – MAss Jan 24 '19 at 16:58
  • exact same error? – dirkgroten Jan 24 '19 at 16:59
  • no, now it does not put "unable to execute 'x86_64-linux-gnu-gcc': No such file or directory" at the end and put `/usr/bin/ld: no se puede encontrar -lssl` `/usr/bin/ld: no se puede encontrar -lcrypto` `collect2: error: ld returned 1 exit status` – MAss Jan 24 '19 at 17:06
  • Check which version of python3-dev is installed: `dpkg -s python3-dev` it's strange you're missing so many libraries. It could be that you should install `python3.6-dev` instead. If it's 3.6, then try installing `libssl-dev`. And continue for each error you get. – dirkgroten Jan 24 '19 at 17:22
  • 1
    this is strange, i just installed it without any issue on Ubuntu 18.0.4 with the default python (3.6). Exactly by installing `python3-dev gcc default-libmysqlclient-dev`. Those were enough. – dirkgroten Jan 24 '19 at 17:43
  • 1
    I don't know why I didn't have those libraries installed but I installed `libssl-dev` and it worked! Thank you! ;) – MAss Jan 25 '19 at 07:51

7 Answers7

29

gcc is part of the build-essential package, which you should install before anything else:

sudo apt-get install build-essential

UPDATE: Following @bosnjak's suggestion, you also might need to install the openssl developer tools:

sudo apt-get install libssl-dev
dirkgroten
  • 20,112
  • 2
  • 29
  • 42
  • 8
    Even after installing all of the above, it didn't work for me in Ubuntu 18.04, until I did `sudo apt install libssl-dev`, which fixed the issue. – bosnjak Dec 09 '19 at 10:25
  • @bosnjak solution worked thanks !! I was trying to install on fresh ubuntu 18.04 installation – psakrii Dec 11 '19 at 05:27
  • @bosnjak Yes! That's exactly what the problem was. The traceback states `cannot find -lssl`, so you really need to install `libssl-dev` to build mysqlclient on Ubuntu. – drec4s Jan 21 '20 at 12:56
22

I specified the particular version of python it's 3.7 And that helped me

I have installed these ones:

sudo apt-get install python3.7-dev libmysqlclient-dev

And then installed mysqlclient by:

pip install mysqlclient
AlexKh
  • 546
  • 2
  • 9
  • 20
10

I turned out, that the solution is slightly different for almost every Python version. For those using different versions, such as Python 2.x, 3.5 or 3.7 I found this:

Part I

For Python 2.x use:

  $ sudo apt-get install python-dev

For Python 2.7 use:

  $ sudo apt-get install libffi-dev

For Python 3.x use:

  $ sudo apt-get install python3-dev

For Python 3.4 use:

  $ sudo apt-get install python3.4-dev

For Python 3.7 use:

  $ sudo apt-get install python3.7-dev

For Python 3.8 use:

  $ sudo apt-get install python3.8-dev

For Python 3.9 use:

  $ sudo apt-get install python3.9-dev

Part II

If this still doesn't help, others have pointed out to install

  $ sudo apt-get install build-essential

and finally

  $ sudo apt-get install libssl-dev

But the last two didn't help myself - but hoping this might help you!

david
  • 2,529
  • 1
  • 34
  • 50
2

You may do this before:

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

Source: https://pypi.org/project/mysqlclient/

1

This issue was persistent in Ubuntu and python 3+. In my case, I was using Ubuntu 18.04 and found this solution to be useful for python version 3.7.5

Step 1. Install libpython3.7-dev via sudo apt

> sudo apt-get install libpython3.7-dev

Step 2: Install mysqlclient

> python3 -m pip install mysqlclient==1.4.6
0

I wanted to install the 'Modoboa' mail-server package (https://github.com/modoboa/modoboa) on my Ubuntu 18.04 with Apache as my webserver, instead of nginx. I needed mysqlclient for Python 2.7. The following packages worked for me:

sudo apt-get install libssl-dev gcc python2.7-dev libmysqlclient-dev
Moray
  • 91
  • 6
0

I'm using the python3.8. Similarly to david's answer, use the following command then it works.

$ sudo apt-get install python3.8-dev

Tianzi
  • 1
  • 1