Installing MySQL Python on Mac OS X - python

Long story short, when I write the following:
sudo easy_install MySQL-python
I get the error
EnvironmentError: mysql_config not found
All right, so there are plenty of threads and the like on how to fix that, so I run this code:
export PATH=$PATH:/usr/local/mysql/bin
Then I rerun my sudo code:
sudo easy_install MySQL-python
Then I get the following error.
Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1
Google/Stack Overflow that, and I am told to download a GCC package which I did the other day, 200 MB's or there-abouts and still no fix.
At this point I am lost, they say insanity is doing the same thing over and over while expecting a different result. Well, I've continually run the aforementioned code expecting a different result, so I'm not to far away from going insane.
At this point in my Python career, I am new to this, but I am willing to try pretty much anything to get this up and running.
If it helps I am officially running, Mac OS X 10.7.5, and I do have MAMP installed (is that an issue?)
Also, the other day when I was trying all of this for the first time I installed (reinstalled?) MySQL, so I'm really in a tough spot at this point.
Is there a fix?
I've racked my brain, searched Google, read Stack Overflow, and spent hours trying to figure this out to no avail.

Here's what I would install, especially if you want to use homebrew:
XCode and the command line tools (as suggested by #7stud, #kjti)
Install homebrew
brew install mysql-connector-c
pip install mysql-python

Another option is to use pymysql it is a pure Python client connection to MySQL so you don't have to mess around with compiling, a good exercise, but it can be frustrating if you are just trying to get something done. pymysql follows the same API as MySQLdb, it can essentially be used as a drop in replacement.
Also, it used to be that MySQLdb, did not work with Python 3, but this may have changed, pymysql didn't have that problem which also induced me to switch, this may have changed though. pymysql can be slower than MySQLdb but you'll have to see if you notice that, it is also under a different license (MIT for pymysql, GPL for MySQLdb)

For Python 3+ the mysql-python library is broken. Instead, use the mysqlclient library. Install with: pip install mysqlclient
It is a fork of mysql-python (also known as MySQLdb) that supports Python 3+
This library talks to the MySQL client's C-interface, and is faster than the pure-python pymysql libray.
Note: you will need the mysql-developer tools installed. An easy way to do this on a Mac is to run
brew install mysql-connector-c
to delegate this task to homebrew. If you are on linux, you can install these via the instructions at the mysqlclient github page.

Install mysql via homebrew, then you can install mysql python via pip.
pip install MySQL-python
It works for me.

I am using OSX -v 10.10.4. The solution above is a quick & easy.
Happening OSX does not have the connection library by default.
First you should install the connector:
brew install mysql-connector-c
Then install with pip mysql
pip install mysql-python

To install PyMySQL
install pip => sudo easy_install pip
install PyMySQL=> sudo easy_install-3.7 pymysql
terminal command to check whether installed or not => pip3 list
or
install PyMySQL=> sudo pip install PyMySQL
terminal command to check whether installed or not => pip3 list
MySQL
The macOS Sierra Public Beta’s didn’t play well with MySQL 5.7.x, but these issues are now resolved by using MySQL 5.7.16
MySQL doesn’t come pre-loaded with macOS Sierra and needs to be dowloaded from the MySQL site.
( https://dev.mysql.com/downloads/mysql/)
The latest version of MySQL 5.7.16 does work with the public release of macOS.
If you already have MySQL 5.7 and you have upgraded OS from El Capitan to Sierra I expect that to be ok, but will be interested if anyone comments on that.
Use the Mac OS X 10.11 (x86, 64-bit), DMG Archive version (works on macOS Sierra).
If you are upgrading from a previous OSX and have an older MySQL version you do not have to update it. One thing with MySQL upgrades always take a data dump of your database in case things go south and before you upgrade to macOS Sierra make sure your MySQL Server is not running.
When downloading you don’t have to sign up, look for » No thanks, just take me to the downloads! – go straight to the download mirrors and download the software from a mirror which is closest to you.
Once downloaded open the .dmg and run the installer.
When it is finished installing you get a dialog box with a temporary mysql root password – that is a MySQL root password not a macOS admin password, copy and paste it so you can use it. But I have found that the temporary password is pretty much useless so we’ll need to change it straight away.
You are also told:
If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.(https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html)
Change the MySQL root password
Note that this is not the same as the root or admin password of macOS – this is a unique password for the mysql root user, use one and remember/jot down somewhere what it is.
Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
if stop throws permission issue
Check the error file first.
tail -f /usr/local/mysql/data/*.err
Do a complete shut down or kill the process. Confirm that no mysql process is running
mysqladmin -uroot shutdown
sudo killall mysqld
ps -ef | grep mysql
Give permisiions
sudo chown -RL root:mysql /usr/local/mysql
sudo chown -RL mysql:mysql /usr/local/mysql/data
chmod -R 755 /usr/local/mysql/data
chmod -R 755 /usr/local/mysql/data/accountname.local.pid
or Right click->get info and change the permission for
/usr/local/mysql/data
/usr/local/mysql/data/Pushparajas-MacBook-Pro.local.pid
Start mysql
sudo mysql.server start
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and log in with a password which is temporary generated:
mysql -u root -p
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass'
;
Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.
\q
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
You can then start the MySQL server from the System Preferences or via the command line.
Command line start MySQL.
sudo /usr/local/mysql/support-files/mysql.server start
To find the MySQL version from the terminal, type at the prompt:
/usr/local/mysql/bin/mysql -v -uroot -p
This also puts you in to a shell interactive dialogue with mySQL, type \q to exit.
After installation, in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path, (optional step) this is done in your “.bash_profile” file in your home directory, if you don’t have that file just create it using vi or nano:
cd ; nano .bash_profile
export PATH="/usr/local/mysql/bin:$PATH"
The first command brings you to your home directory and opens the .bash_profile file or creates a new one if it doesn’t exist, then add in the line above which adds the mysql binary path to commands that you can run. Exit the file with type “control + x” and when prompted save the change by typing “y”. Last thing to do here is to reload the shell for the above to work straight away.
source ~/.bash_profile
mysql -v
You will get the version number again, just type “q” to exit.
Fix the 2002 MySQL Socket error
Fix the looming 2002 socket error – which is linking where MySQL places the socket and where macOS thinks it should be, MySQL puts it in /tmp and macOS looks for it in /var/mysql the socket is a type of file that allows mysql client/server communication.
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
phpMyAdmin
uncomment below line in httpd.conf file
LoadModule php7_module libexec/apache2/libphp7.so
First fix the 2002 socket error if you haven’t done so from the MySQL section-
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Download phpMyAdmin, (https://www.phpmyadmin.net/downloads/) the zip English package will suit a lot of users, then unzip it and move the folder with its contents into the document root level(~/Sites/) renaming folder to ‘phpmyadmin’.
Make the config folder
mkdir ~/Sites/phpmyadmin/config
Change the permissions
chmod o+w ~/Sites/phpmyadmin/config
Run the set up in the browser
http://localhost/~username/phpmyadmin/setup/ or http://localhost/phpmyadmin/setup/
You need to create a new localhost mysql server connection, click new server.
Switch to the Authentication tab and set the local mysql root user and the password.
Add in the username “root” (maybe already populated, add in the password that you set up earlier for the MySQL root user set up, click on save and you are returned to the previous screen.
(This is not the macOS Admin or root password – it is the MySQL root user).
Make sure you click on save, then a config.inc.php is now in the /config directory of phpmyadmin directory, move this file to the root level of /phpmyadmin and then remove the now empty /config directory.
In the latest phpmyadmin, download the config.inc.php and place in phpmyadmin directory.
If you want to setup new server move config.inc.php to some location and try http://localhost/~username/phpmyadmin/setup
Now going to http://localhost/~username/phpmyadmin/ will now allow you to interact with your MySQL databases.
To upgrade phpmyadmin just download the latest version and copy the older ‘config.inc.php‘ from the existing directory into the new folder and replace – backup the older one just in case.
Permissions
To run a website with no permission issues it is best to set the web root and its contents to be writeable by all, since it’s a local development it shouldn’t be a security issue.
Lets say that you have a site in the User Sites folder at the following location ~/Sites/testsite you would set it to be writeable like so:
sudo chmod -R a+w ~/Sites/testsite
If you are concerned about security then instead of making it world writeable you can set the owner to be Apache _www but when working on files you would have to authenticate more as admin you are “not” the owner, you would do this like so:
sudo chown -R _www ~/Sites/testsite
This will set the contents recursively to be owned by the Apache user.
If you had the website stored at the System level Document root at say ~/Sites/testsite then it would have to be the latter:
sudo chown -R _www ~/Sites/testsite
Another easier way to do this if you have a one user workstation is to change the Apache web user from _www to your account.
That’s it! You now have the native AMP stack running on top of macOS Sierra.
Ref Link - https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/#ssu

On Mojave, I ran into errors with finding the SSL libraries, here's what finally worked without having to modify mysql_config:
sudo pip install MySQL-Python --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib"
Hopefully that will save someone a few hours of heartache

It's time to be a big boy and install from source. Try this:
1) Download the MySQL-python-1.X.X.tar.gz file(by default will go to your Downloads directory)
2) Open a Terminal window and cd to the Downloads directory.
3) Unzip the file you downloaded:
~/Downloads$ tar xfvz MySQL-python-1.X.X.tar.gz
That will create a directory inside your Downloads directory called MySQL-python
4) cd into the newly created directory.
5) Typically, you just open the file called README or INSTALL and follow the instructions--but generally to install a python module all you do is:
$ sudo python setup.py install
If you care to look, there should be a file called setup.py inside your newly created MySQL-python directory, and you are invoking that program to install the module.
Also note that this:
export PATH=$PATH:/usr/local/mysql/bin
is not permanent if you did that on the command line. You need to put that line in a file called .bashrc in your home directory (~/ or equivalently /Users/YOUR_USER_NAME). To see if .bashrc already exists(it's a hidden file), issue the command:
$ ls -al
and look for .bashrc. If .bashrc doesn't exist, then create it.

As others mentioned before me....getting Python to work with MySQL on a Mac is a ?##$#&%^!! nightmare.
Installed Django framework on Mac OS 10.7.5 initially from the original Django website and when the MySQLdb didn't work, and after many hours googling and trying solutions from SO, I have installed the Django stack from BitNami http://bitnami.com/stack/django
Still, got the issues mentioned above and then some more...
What helped me eventually is what Josh recommends on his blog: http://joshbranchaud.com/blog/2013/02/10/Errors-While-Setting-Up-Django.html
Now Python 2.7 is finally connected to MySQL 5.5

The issue you are having is that the gcc compiler is not installed on your Mac. It will be installed if you have installed XCode. You will have to download gcc complier and install it manually. Follow the below link and download it -
https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg
I once had this problem installing Ruby 1.9 and I had to compile ruby for myself because Mountain Lion wasn't supported at that time. After installing the package, verify the install by the command gcc.

I am using Python 2.7.11 :: Anaconda 2.3.0 (x86_64) on Mac OS X 10.11.4 15E65.
You may want to follow the steps below:
Install homebrew
Open a terminal and run: brew install mysql-connector-c
pip install mysql-python
Then the Anaconda will have the mysql-python installed and you can start with MySQLdb then.
Good luck. Thanks.

Above all, I can't solve it. But I add file to /usr/local/include solve it.
https://github.com/peterlee0304/MySQL-Python/blob/master/my_config.h
In /usr/local/include, add a my_config.h file.
Then pip install MySQL-Python
Solve it!

What worked for me is:
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python

the below may be help.
brew install mysql-connector-c
CFLAGS =-I/usr/local/Cellar/mysql-connector-c/6.1.11/include pip install MySQL-python
brew unlink mysql-connector-c

I used PyMySQL instead and its working fine!
sudo easy_install-3.7 pymysql

Related

Install Python 3 on Cloudready/Chromium/Chrome OS without installing Linux containers/environments

Recently I installed Neverware's version of Chromium OS, called Cloudready, on VirtualBox 6.1, to develop Python apps for Chromebooks. This version of Chromium OS is 48.0.2564.116 developer build (newer versions won't install due to graphics incompatibilities). As I do not have a Google Account, I login into Chromium OS as Guest user (somehow I have administrative powers as Guest, which is good for my developmental purposes).
I found that Python 2.7.3 was preinstalled. I tried to install Python 3.6, and to do so, I tried to find the preinstalled package manager, which I eventually found. The package manager that is preinstalled (portage), doesn't install anything, because it gives errors similar to this one:
chronos#localhost / $ sudo emerge dev-lang/python:3.6
!!! PORTAGE_BINHOST unset, but use is requested.
!!! Problem with sandbox library. Disabling...
Calculating dependencies... done!
WARNING: A requested package will not be merged because it is listed in
package.provided:
dev-lang/python:3.6 pulled in by 'args'
>>> Auto-cleaning packages...
>>> No outdated packages were found on your system.
chronos#localhost / $
I tried installing Python PIP for Python 2 from the get-pip.py script provided here, and it worked. Because I want to create graphical interfaces for my programs for Chromebooks, I wanted to install the tkinter module, and because I didn't want the users of my programs to have to use the Terminal to execute my Python programs and install Python modules, I wanted to install PyInstaller. I wanted to install PyInstaller through PIP, but PIP throws the following error for any attempted module installation:
/usr/local/lib64/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py:387: SNIMissingWarning: An HTTPS requ
est has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. Thi
s may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can up
grade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/l
atest/advanced-usage.html#ssl.warnings
SNIMissingWarning,
/usr/local/lib64/python2.7/site-packages/pip_vendor/urllib3/util/ssl_.py:142: InsecurePlatformWarning: A true
SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause cert
ain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information,
see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning,
When trying to install PyInstaller, PIP actually managed to collect the pyinstaller-4.0.tar.gz package, but it fails upon installation because the PyInstaller installer raises an exception/error BackendUnavailable, and then PIP raises the InsecurePlatformWarning error again. As pointed out by #BryanOakley, I cannot install Tkinter from PIP, which I forgot while I was using Chromium OS (for example, the command to install Tkinter on Ubuntu is sudo apt-get install python3-tk), which makes things even trickier.
From the errors raised, it appears that I have to install a newer version of Python (which I have already tried, to no avail). I tried to install Python 3 by installing Anaconda 3 and then Miniconda 3, but both provide the same error, and I have even looked through Stack Overflow and what people had voted as the answer still did not work for me. The following commands...
$ mkdir ~/Downloads/TMP
$ TMPDIR=~/Downloads/TMP sudo bash ~/Downloads/Miniconda3-latest-Linux-x86_64.sh -p /usr/local/miniconda3
...eventually result in this output:
/usr/local/miniconda3/conda.exe: error while loading shared libraries: libz.so.1: failed to segment from sh
ared object: Operation not permitted
/usr/local/miniconda3/conda.exe: error while loading shared libraries: libz.so.1: failed to segment from sh
ared object: Operation not permitted
Nothing has worked thus far. How can I successfully install Python 3.6 with Tkinter and PyInstaller on Chromium OS Version 48 without installing Linux containers/environments (such as the option to install the official Linux (Beta) or Crouton) or installing anything from the Google Play Store?
There can be 2 possibilities:
1). The python3.6 is already installed.
WARNING: A requested package will not be merged because it is listed in
package.provided:
To check that try:
which python3
or simply try running
python3.
2). uninstalling python2 so that the merge will not even be necessary can also help you out.
The answer that explains why Miniconda doesn't install was correct that /tmp is mounted as noexec (mounted with no executable permission). Unfortunately, their suggested approach to fix it (specify a different TMPDIR directory for installation) did not work for me. However, I eventually managed to find a different approach.
So, reboot the Chromebook and enter Developer Mode. Open the Crosh (Chrome Developer Shell) and type in the command shell to access the hidden Bash shell (as I am using Chromium OS developer build, not Chrome OS, I do not need to enter a developer mode to access the Bash shell).
Now, instead of specifying a different TMPDIR directory as suggested in the answer I've referenced earlier, remount tmp as exec (with executable permission):
sudo mount /tmp -o remount,exec
When prompted for a password, type in the password for user chronos. There are (apparently) several different default passwords for chronos, including facepunch, password, chrome, localhost, test0000, and a blank password (nothing). In my case it was chrome. If you are using an official Chromebook and have booted into Developer Mode, you should have set a password with chromeos-setdevpasswd when enabling Developer Mode (for more information click here).
After that, download the Miniconda installation script for Linux from the Conda website (remember to download the 64-bit version though), change the working directory to the location of the downloaded Miniconda installation script file, run it, and change the install location to a location with write privileges (in my case /usr/local/conda3).
cd ~/Downloads
sudo bash ~/Downloads/Miniconda3-latest-Linux-x86_64.sh -p /usr/local/conda3
When installation finishes, you must add your Conda installation to PATH:
echo "PATH=/usr/local/conda3/bin:$PATH" >> ~/.bashrc
Restart the Crosh and enter the Bash shell again. Verify that the directory of the installed Conda binaries is in PATH with echo $PATH and if /usr/local/conda3/bin is in PATH, verify that Python is installed with python3 --version.
Now it is time to install other modules. The installation of Miniconda includes the package manager Conda which specifically installs Python packages (however, there are some other packages available in Conda, such as GCC). Using Conda, you can install Tkinter, PyInstaller, and many other Python packages:
conda install -c anaconda tk
conda install -c anaconda pyinstaller
Installing PyInstaller works, but it appears that on Chromium OS, there is no such tool as objcopy, meaning that PyInstaller cannot compile any Python scripts, and, as explained in the PyInstaller requirements, ldd, objcopy, and objdump must be installed for PyInstaller to work on Linux installations. The workaround for this is to compile Python scripts with PyInstaller on another Linux computer and then run the compiled script on Chrome/Chromium OS.
Also, on newer versions of Chromium OS, graphical Python applications (made with Tkinter, PyQt, etc.) don't run because they don't recognise the system DISPLAY environment variable. The problem is that the entire graphical display of Chrome/Chromium OS is controlled by the Google Chrome web browser program and the web browser runs with no DISPLAY variable, meaning that any GUI program started in the OS by the user (meaning that it would be started by the Chrome browser) would start with no DISPLAY variable.
The workaround is to set the DISPLAY variable for the Chrome browser. To do this, you will need to login as root with the command sudo su, as Crosh does not allow editing the file you will need to edit, even with the sudo command. After logging in as root with sudo su, you will need to run the following commands:
mount -o remount,rw /dev/root /
echo "DISPLAY=:0" >> /etc/chrome_dev.conf
Then reboot, and now you should be able to run graphical Python programs as well as console Python programs.

MySQL Utilities with MySQL 8 Server

As part of our build process, we use the mysqldiff utility (invoked from maven) to validate our database migration scripts by comparing a freshly-built copy of the schema to a version of the schema created from a baseline plus our migration script. This all works fine with MySQL 5.7.
We are looking to upgrade to MySQL 8.0.13. The database user has been configured to use mysql_native_password. When we run our build, we are getting this error from mysqldiff:
ERROR: Authentication plugin 'caching_sha2_password' is not supported
We understand that this error is due to the fact that the utility is using an old version of mysql-python-connector. We also understand that the answer might be as simple as upgrading the connector version, but we don't know how to go about trying that.
The MySQL Utilities can be found at https://github.com/mysql/mysql-utilities.
On Windows 10, we install using the Oracle windows installer. On Amazon Linux, we install with yum.
NOTE:
The MySQL Utilities appear to be based on an embedded python2.7 installation (we do not have standalone python installed on any of the development or build machines).
We do not have python expertise, so detailed steps will be helpful if we are mucking with the embedded python stuff.
We need to solve this problem both on Windows 10 and Amazon Linux.
How do we work around this error so that we can use mysqldiff with a MySQL 8.0.13 server on Windows 10 and Amazon Linux?
If the answer is simply to upgrade the connector, what are the detailed steps for doing that?
Are there server installation/configuration changes we can make to support clients connecting with old drivers?
I have managed to run mysqldiff.py against mysql 8, with some patches:
clone the patched source code and enter its dir:
$ git clone https://github.com/georgexsh/mysql-utilities.git
create a virtualenv and activate it:
$ virtualenv -p python2 venv
$ . venv/bin/activate
install the newer mysql connector:
(venv) $ pip install mysql-connector-python>=8.0
install mysql-utilities to the current virtualenv:
(venv) $ pip install .
now mysqldiff.py is able to run. if you want to run without activate virtualenv, you use its full path:
/path/to/mysql-utilities/venv/bin/mysqldiff.py
steps under windows are mostly the same, except virtualenv activation:
venv\Scripts\activate.bat
I encountered same problem and looked into mysql python connector code and added class for caching_sha2_password. It works for me now.
1. To fix the issue download source code for mysql-python-connector from Mysql official website, then install python (any version).
2. unzip downloaded mysql-python-connector zip file, and inside you will find setup.py
3. Open terminal and type python setup.py install
4. build folder will be created in current folder. Go to build/mysql/ and copy authentication.py file
5. open Mysql Utilities ->> bin ->> library.zip, and find mysql connector- > mysql > authentication.pyc file and delete i and paste authentication.py file you copied earlier.
6. DONE !
If you dont want to mess with it, you can download ready files from this link
Here is the link for files and explanation.
https://github.com/rgaraisayev/mysqldiff

Unable to install MySQL driver for Python [duplicate]

First off, yeah, I've already seen this:
pip install mysql-python fails with EnvironmentError: mysql_config not found
The problem
I am trying to use Django on a Google App Engine project. However, I haven't been able to get started as the server fails to start properly due to:
ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I did some research and it all pointed to having to install Mysql-python, as apparently it isn't on my system. I actually tried uninstalling it and got this:
Cannot uninstall requirement mysql-python, not installed
Whenever I actually do try to install via:
sudo pip install MySQL-python
I get an error stating:
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
I've already tried running:
export PATH=$PATH:/usr/local/mysql/bin
but that didn't seem to help, as I ran the installation command again and it still failed.
Any ideas?
Please note I'm not in a virtualenv.
Ok, well, first of all, let me check if I am on the same page as you:
You installed python
You did brew install mysql
You did export PATH=$PATH:/usr/local/mysql/bin
And finally, you did pip install MySQL-Python (or pip3 install mysqlclient if using python 3)
If you did all those steps in the same order, and you still got an error, read on to the end, if, however, you did not follow these exact steps try, following them from the very beginning.
So, you followed the steps, and you're still geting an error, well, there are a few things you could try:
Try running which mysql_config from bash. It probably won't be found. That's why the build isn't finding it either. Try running locate mysql_config and see if anything comes back. The path to this binary needs to be either in your shell's $PATH environment variable, or it needs to be explicitly in the setup.py file for the module assuming it's looking in some specific place for that file.
Instead of using MySQL-Python, try using 'mysql-connector-python', it can be installed using pip install mysql-connector-python. More information on this can be found here and here.
Manually find the location of 'mysql/bin', 'mysql_config', and 'MySQL-Python', and add all these to the $PATH environment variable.
If all above steps fail, then you could try installing 'mysql' using MacPorts, in which case the file 'mysql_config' would actually be called 'mysql_config5', and in this case, you would have to do this after installing: export PATH=$PATH:/opt/local/lib/mysql5/bin. You can find more details here.
Note1: I've seen some people saying that installing python-dev and libmysqlclient-dev also helped, however I do not know if these packages are available on Mac OS.
Note2: Also, make sure to try running the commands as root.
I got my answers from (besides my brain) these places (maybe you could have a look at them, to see if it would help): 1, 2, 3, 4.
I hoped I helped, and would be happy to know if any of this worked, or not. Good luck.
I had been debugging this problem forever - 3 hours 17 mins. What particularly annoyed me was that I already had sql installed on my system through prior uni work but pip/pip3 wasn't recognising it. These threads above and many other I scoured the internet for were helpful in eluminating the problem but didn't actually solve things.
ANSWER
Pip is looking for mysql binaries in the Homebrew Directory which is located relative to Macintosh HD #
/usr/local/Cellar/
so I found that this requires you making a few changes
step 1: Download MySql if not already done so https://dev.mysql.com/downloads/
Step 2: Locate it relative to Macintosh HD and cd
/usr/local/mysql/bin
Step 3: Once there open terminal and use a text editor of choice - I'm a neovim guy myself so I typed (doesn't automatically come with Mac... another story for another day)
nvim mysql_config
Step 4: You will see at approx line 112
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
Change to
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
*you'll notice that this file has read-only access so if your using vim or neovim
:w !sudo tee %
Step 5: Head to the home directory and edit the .bash_profile file
cd ~
Then
nvim .bash_profile
and add
export PATH="/usr/local/mysql/bin:$PATH"
to the file then save
Step 6: relative to Macintosh HD locate paths and add to it
cd /private/etc/
then
nvim paths
and add
/usr/local/mysql/bin
*you'll again notice that this file has read-only access so if your using vim or neovim
:w !sudo tee %
then
cd ~
then refresh the terminal with your changes by running
source .bash_profile
Finally
pip3 install mysqlclient
And Viola. Remember it's a vibe.
If you don't want to install full mysql, we can fix this by just installing mysql-client
brew install mysql-client
Once cmd is completed it will ask to add below line to ~/.bash_profile:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
Close terminal and start new terminal and proceed with pip install mysqlclient.
I am running Python 3.6 on MacOS Catalina. My issue was that I tried to install mysqlclient==1.4.2.post1 and it keeps throwing mysql_config not found error.
This is the steps I took to solve the issue.
Install mysql-connector-c using brew (if you have mysql already install unlink first brew unlink mysql) - brew install mysql-connector-c
Open mysql_config and edit the file around line 112
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl - this will give you more information on what needs to be done about putting openssl in PATH
in relation to step 3, you need to do this to put openssl in PATH - echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
for compilers to find openssl - export LDFLAGS="-L/usr/local/opt/openssl/lib"
for compilers to find openssl - export CPPFLAGS="-I/usr/local/opt/openssl/include"
Also this happens when I was installing mysqlclient,
$ pip install mysqlclient
As user3429036 said,
$ brew install mysql
If you have installed mysql using Homebrew by specifying a version then mysql_config would be present here. - /usr/local/Cellar/mysql#5.6/5.6.47/bin
you can find the path of the sql bin by using ls command in /usr/local/ directory
/usr/local/Cellar/mysql#5.6/5.6.47/bin
Add the path to bash profile like this.
nano ~/.bash_profile
export PATH="/usr/local/Cellar/mysql#5.6/5.6.47/bin:$PATH"
This answer is for MacOS users who did not install from brew but rather from the official .dmg/.pkg. That installer fails to edit your PATH, causing things to break out of the box:
All MySQL commands like mysql, mysqladmin, mysql_config, etc cannot be found, and as a result:
the "MySQL Preference Pane" fails to appear in System Preferences, and
you cannot install any API that communicates with MySQL, including mysqlclient
What you have to do is appending the MySQL bin folder (typically /usr/local/mysql/bin in your PATH by adding this line in your ~/.bash_profile file:
export PATH="/usr/local/mysql/bin/:$PATH"
You should then reload your ~/.bash_profile for the change to take effect in your current Terminal session:
source ~/.bash_profile
Before installing mysqlclient, however, you need to accept the XcodeBuild license:
sudo xcodebuild -license
Follow their directions to sign away your family, after which you should be able to install mysqlclient without issue:
pip install mysqlclient
After installing that, you must do one more thing to fix a runtime bug that ships with MySQL (Dynamic Library libmysqlclient.dylib not found), by adding this line to your system dynamic libraries path:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
brew install mysql added mysql to /usr/local/Cellar/..., so I needed to add :/usr/local/Cellar/ to my $PATH and then which mysql_config worked!
The problem in my case was that I was running the command inside a python virtual environment and it didn't had the path to /usr/local/mysql/bin though I have put it in the .bash_profile file. Just exporting the path in the virtual env worked for me.
For your info sql_config resides inside bin directory.
Install brew or apt-get is also not easy for me so I downloaded mysql via: https://dev.mysql.com/downloads/connector/python/, installed it. So I can find mysql_config int this directory: /usr/local/mysql/bin
the next step is:
export PATH=$PATH:/usr/local/mysql/bin
pip install MySQL-python==1.2.5

unable to get pip to work in a shared hosting environment

I was hoping someone might be able to provide a resource that will help me install python 3.6.0 on a shared hosting account at Bluehost. I’ve tried using the documentation for python 2.7 but have been unsuccessful to date. The current state of the machine now is if I run python –V it says 2.6.6 . If, however I place:
export PATH=$HOME/python/Python-3.6.0/:$PATH
in the .bashrc file in my home directory and then run python –V it says 3.6.0 However I am unable to get pip to work. I also noticed that during the python setup procedure permission was denied on a number of files.
I am really at a lost as there seems to be very little documentation for how to do this on a shared hosting environment. Your help would be greatly appreciated.
here's a link to the instructions I followed python
I thought pip would be installed as it said pip 9.0.2 was installed but when I try to run it it say cxommand not found. When I tried easy_install pip I got back the following error message:
[Errno 30] Read-only file system: '/usr/lib/python2.6/site-packages/test-easy-install-13141.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib/python2.6/site-packages/
You cannot install the package because it is trying to install them in the system directory, and you do not have write access.
If you can, use a virtualenv. Of course this requires virtualenv be installed.
Put the virtualenv somewhere you have write access to. For example, use these instructions.
Enter the following commands to download and extract Python
3.6 to your hosting account.
mkdir ~/python
cd ~/python
wget http://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar zxfv Python-3.6.0.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.6.0
Install Python
Once extracted you can use the following commands to
configure and install Python.
./configure --prefix=$HOME/python
make
make install
Modify the .bashrc
For your local version of python to load you will need to add
it to the .bashrc file.
vim ~/.bashrc
Press i
Enter:
export PATH=$HOME/python/Python-3.6.0/:$PATH
export PYTHONPATH=$PYTHONPATH:$HOME/python/python3.6/site-packages/
Write the changes (press ESC) and close vim:
:wq
Press Enter
source ~/.bashrc
Now to use pip:
python -m pip install package-of-interest
You could also ask the system administrator to install the package for you. This might be the only real option if virtualenv hasn't been installed. Ask the administrator to install virtualenv.

How to install OpenERP on Mac OS X Mavericks?

I want to install OpenERP v7 on Mac OS X. How can I install it?
I tried to install it brew install postgresql I succeed to install postgresql but when I create the user with following command createuser openerpI got the error like
createuser:command not found I also got an error when I type psql.
Note: OpenERP is now called Odoo.
Make sure you have brew installed.
brew install postgresql
postgres -D /usr/local/var/postgres or launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
createdb odootest (not really needed if you use sample data)
git clone https://github.com/odoo/odoo.git, the repo is 500MB big so this takes a while
cd odoo
git checkout origin/7.0 switch to 7.0 branch (this should be a better command because it leaves me in detached head, please edit)
sudo python setup.py install, this will also install many dependencies with easy_install, ignore all the warnings
python openerp-server -s to start with sample data generated by odoo. If you
I also had to sudo easy_install pyPdf but I'm not sure if that's because I first tried the master branch. If you experience errors for missing libraries simply easy_install them.
Install PostgreSQL
Create a user for OpenERP
Install all dependencies for Python, using brew or MacPorts
Download OpenERP and extract it
Run the following command: cd openerp; python openerp-server

Categories

Resources