This question already has answers here:
pip install mysql-python fails with EnvironmentError: mysql_config not found
(24 answers)
Closed 3 years ago.
I have been trying for a few days to fix this, looking at other questions but I can't find a question wth the same error that I am getting.
I have been attempting to follow this tutorial https://realpython.com/learn/start-django/ and get to this point:
Database settings
First, install MySQL-python, which is a database connector for Python:
$ pip install MySQL-python
Everything has worked okay up to here but when I try and install MySQL-python I get the following error:
(env) Camerons-MacBook-Pro:django15_project camrail$ pip install MySQL-python
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/
(env) Camerons-MacBook-Pro:django15_project camrail$
I found this answer https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/ that says the MySQL utilities are not made available, so I followed their advice to fix it but to no avail. I have also tried installing developer tools xcode-select --install as some have suggested. I have tried reinstalling ez_setup.
Not really sure where to go from here, any help greatly appreciated.
In my opinions mysql_config is missing on your system or the installer could not find it. Please Be sure mysql_config is really installed.
For instance,
On Debian/Ubuntu, You must install the package:
sudo apt-get install libmysqlclient-dev
Running Mac OSX Mountain Lion, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
This is the quickest fix I found.
I was also getting the same error while installing the mysql package by pip But after installing libmysqlclient-dev
sudo apt install libmysqlclient-dev
pip install mysql
Now it worked for me..
verified:
import mysql
did not find any error, Means got installed successfully and working
properly
Check your mysql configuration file using this:
mysql_config
Now you should get an output something like this:
mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Compiler: GNU 6.3.0
Options:
--cflags [-I/usr/include/mysql ]
--cxxflags [-I/usr/include/mysql ]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--libs_r [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--plugindir [/usr/lib/mysql/plugin]
--socket [/var/run/mysqld/mysqld.sock]
--port [0]
--version [5.7.18]
--libmysqld-libs [-L/usr/lib/x86_64-linux-gnu -lmysqld -lpthread -lz -lm -lrt -latomic -lcrypt -ldl -laio -llz4 -lnuma]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib/x86_64-linux-gnu]
plugindir [/usr/lib/mysql/plugin]
Ideally it should contain libmysqld-libs option. If it is not there, as it was not there in my case, you can assume that your mysql is broken.
In this case you can write this configuration to config file directly
If you are using Windows OS download and install mysql-python directly from here .
Not sure if it useful. But it help me to solve the problem.
apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev
For completeness sake, on Debian Stretch the pkg is now called default-libmysqlclient-dev.
sudo apt-get install default-libmysqlclient-dev
I run the following commands and it worked smooth in Ubuntu 17.10
sudo apt-get install libmysqlclient-dev
pip3 install mysqlclient
Related
Upon attempting to compile python 3.7 I hit Could not import runpy module:
jeremyr#b88:$ wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
....
jeremyr#b88:~/Python-3.7.3$ ./configure --enable-optimizations
jeremyr#b88:~/Python-3.7.3$ make clean
jeremyr#b88:~/Python-3.7.3$ make -j32
....
gcc -pthread -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.7m.a -lcrypt -lpthread -ldl -lutil -lm
./python -E -S -m sysconfig --generate-posix-vars ;\
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
Could not import runpy module
Traceback (most recent call last):
File "/home/jeremyr/Python-3.7.3/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/home/jeremyr/Python-3.7.3/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/home/jeremyr/Python-3.7.3/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
Makefile:603: recipe for target 'pybuilddir.txt' failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory '/home/jeremyr/Python-3.7.3'
Makefile:531: recipe for target 'profile-opt' failed
make: *** [profile-opt] Error 2
jeremyr#88:~/Python-3.7.3$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.11 (jessie)
Release: 8.11
Codename: jessie
jeremyr#88:~/Python-3.7.3$ gcc --version
gcc (Debian 4.9.2-10+deb8u2) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
jeremyr#88:~/Python-3.7.3$ sudo apt upgrade gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... gcc is already the newest version.
jeremyr#b88:~/Python-3.7.3$ echo $PYTHONPATH
Any advice on how to overcome this and install python3.7 appreciated.
Edit - the solution listed below seems to work for various other python versions, so I changed title to python 3.x from 3.7
It seems the enable-optimizations was the problem,
jeremyr#b88:~/Python-3.7.3$ ./configure
jeremyr#b88:~/Python-3.7.3$ make clean
takes care of it in my case.
In case others come across this question: I encountered the same problem on Centos 7. I also had --enable-optimizations but didn't want to remove that flag. Updating my build dependencies and then re-running solved the problem. To do that I ran:
sudo yum groupinstall "Development Tools" -y
In case the yum group is not available, you can also install the pacakges individually using:
sudo yum install bison byacc cscope ctags cvs diffstat doxygen flex gcc gcc-c++ gcc-gfortran gettext git indent intltool libtool patch patchutils rcs redhat-rpm-config rpm-build subversion swig systemtap
For whomever MicGer's answer didn't work and would like to retain --enable-optimizations, check your gcc version. The error was solved for me on gcc 8.3.0.
For me, CentOS 7, compiling Python3.9, the fix was updating the gcc and related packages.
Removing --enable-optimizations didn't solved the issue here, neither upgrading GCC from gcc-7.5.0 to gcc-8.2.1 trying building Python 3.6.13 on opensuse-15.2.
Here for some reason the build is picking a local python installation, so before calling make I have updated the PATH env to include the build directory (were python file is generated), for instance: export PATH=$(pwd):$PATH
I'm trying to install MySQLdb for Python on Mac OS.
When I digit pip install MySQL-python shell returns to this:
Collecting MySQL-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/setup.py", line 17, in
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/
What can I do? I searched everywhere but I couldn't find an answer.
(I had installed Python 2.7)
I fixed the error. If anyone have this error just follow these steps:
First of all install mysql connector
brew install mysql-connector-c
You have to modify lines in mysql_config (this is an alias)
vim /usr/local/bin/mysql_config
(I sincerely consider to open mysql_config with a file editor, you can find the
exact folder here)
/usr/local/Cellar/mysql-connector-c/6.1.11/bin/
Replace these lines.
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
should be:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
Set environment variable
brew info openssl
it would tell what’s needed
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
Then you can install MySQL
pip install MySQL-python
You can test if MySQL is installed with this:
python -c "import MySQLdb"
Hope this works also for you!
I tried to install Kivy on my computer but unfortunately I failed.
I'm running MacOS (v10.13.4) and I have installed Cython successfully (v0.26).
I ran:
pip3 install kivy
Then the process starts and the following error occurs:
**Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/yl/kw3svt1x4rdfdjzsd5hds9_c0000gn/T/pip-req-build-869vs3u5/**.
Is it possible to fix it?
As asked in the comments I'm posting the complete error trace:
`**Command Collecting kivy
Using cached https://files.pythonhosted.org/packages/8c/49/5c22589099f9b7fd106502ee6634a6675e634d7553fede141a7606e6a92d/Kivy-1.10.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/yl/kw3svt1x4rdfdjzsd5hds9_c0000gn/T/pip-install-nowxhf43/kivy/setup.py", line 668, in <module>
base_flags = determine_base_flags()
File "/private/var/folders/yl/kw3svt1x4rdfdjzsd5hds9_c0000gn/T/pip-install-nowxhf43/kivy/setup.py", line 551, in determine_base_flags
xcode_dev = getoutput('xcode-select -p').splitlines()[0]
IndexError: list index out of range
Using distutils
Detected Cython version 0.26
This version of Cython is untested with Kivy. While this version may
work perfectly fine, it is possible that you may experience issues. If
you do have issues, please downgrade to a supported version. It is
best to use the newest supported version, 0.25.2, but the minimum
supported version is 0.23.
If your platform provides a Cython package, check if you can downgrade
to a supported version. Otherwise, uninstall the platform package and
install Cython via pip:
pip install -I Cython==0.25.2
User distribution detected, avoid portable command.
Using this graphics system: OpenGL ES 2
OSX framework used, force to x86_64 only
OSX ARCHFLAGS are: -arch x86_64
GStreamer framework not found, fallback on pkg-config
WARNING: A problem occurred while running pkg-config --libs --cflags gstreamer-1.0 (code 127)
b'/bin/sh: pkg-config: command not found\n'
Missing framework /Library/Frameworks/SDL2.framework
Missing framework /Library/Frameworks/SDL2_ttf.framework
Missing framework /Library/Frameworks/SDL2_image.framework
Missing framework /Library/Frameworks/SDL2_mixer.framework
SDL2 frameworks not found, fallback on pkg-config
WARNING: A problem occurred while running pkg-config --libs --cflags sdl2 SDL2_ttf SDL2_image SDL2_mixer (code 127)
b'/bin/sh: pkg-config: command not found\n'
WARNING: A problem occurred while running xcode-select -p (code 2)
b'xcode-select: error: unable to get active developer directory, use `sudo xcode-select --switch path/to/Xcode.app` to set one (or see `man xcode-select`)\n'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/yl/kw3svt1x4rdfdjzsd5hds9_c0000gn/T/pip-install-nowxhf43/kivy/**`
Trying to follow a Django tutorial but I cannot install mysqlclient.
The tutorial claims that I can do so with the following command:
pip install mysqlclient
but this generates this error:
Collecting mysqlclient Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrolctwh/mysqlclient/
I have the most up-to-date pip and virtualenv installed.
I would like to be able to install mysqlclient so that I may continue with the tutorial.
You should also install the mysql and python development headers and libraries:
https://github.com/PyMySQL/mysqlclient-python#prerequisites
I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me
but just to clarify I was running python 3.5 from a virtual environment
and after installing the prerequisites, it all worked fine
The following solved it for me :
You may need to install the Python 3 and MySQL development headers and libraries like so:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
Source : https://github.com/PyMySQL/mysqlclient#prerequisites
I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:
yum list installed |grep MariaDB
MariaDB-client.x86_64 10.2.7-1.el6 #bull
MariaDB-common.x86_64 10.2.7-1.el6 #bull
MariaDB-compat.x86_64 10.2.7-1.el6 #bull
MariaDB-devel.x86_64 10.2.7-1.el6 #bull
MariaDB-server.x86_64 10.2.7-1.el6 #bull
And the issue was resolved.
I am trying to install pycurl on OS X Mavericks. I have downloaded and installed the Xcode dev tools to have some compiler. I went into the Xcode preferences and made sure that I have downloaded all the compliers I would need but still getting this error
When I try to install pycurl I get the following errors. Any help would be much appreciated.
local-mbp:~ $ sudo easy_install pycurl
Password:
Searching for pycurl
Reading http://pypi.python.org/simple/pycurl/
Best match: pycurl 7.19.3.1
Downloading https://pypi.python.org/packages/source/p/pycurl/pycurl-7.19.3.1.tar.gz#md5=6df8fa7fe8b680d93248da1f8d4fcd12
Processing pycurl-7.19.3.1.tar.gz
Running pycurl-7.19.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-jKMmtE/pycurl-7.19.3.1/egg-dist-tmp-9z89Ns
Using curl-config (libcurl 7.30.0)
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: Setup script exited with error: command 'cc' failed with exit status 1
local-mbp:~ $ which gcc
/usr/bin/gcc
local-mbp:~$ which cc
/usr/bin/cc
local-mbp:~$
Try this:
brew install python
Double check you are using brewed Python:
which python
(Should return something like /usr/local/bin/python)
Install pycurl with pip.
pip install pycurl
I just tested this on Mavericks.
Try specify the ARCHFLAGS env var:
ARCHFLAGS="-arch x86_64" pip install pycurl