Ikaru
Ikaru

Reputation: 21

How to Correctly install MySQL module in Python

I am new to coding and ubuntu, and I am trying to insert some data to MySQL using Python, but I am having some error in installing the mysql module.

I am having this error:

**pip install mysql**
Defaulting to user installation because normal site-packages is not writeable
Collecting mysql
  Using cached mysql-0.0.2.tar.gz (1.9 kB)
Collecting mysqlclient
  Using cached mysqlclient-2.0.2.tar.gz (88 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"'; __file__='"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ocgktfp6
         cwd: /tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/
    Complete output (12 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 65, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Upvotes: 2

Views: 1798

Answers (2)

Santhosh Reddy
Santhosh Reddy

Reputation: 135

pip install mysql-connector-python try this , if you are still facing the issue, check your python version, make sure it is python3.8 and above.

Upvotes: 2

Michael Hill
Michael Hill

Reputation: 23

Hello and welcome to Python! A popular library used for interacting with MySQL database servers is "PyMySQL" and this can be found at: https://pypi.org/project/PyMySQL/

Installation Command:

pip install pymysql

You can view example usage here: https://pypi.org/project/PyMySQL/#example

Upvotes: 0

Related Questions