I have worked many hours over several days trying to get MySQL working with Mac OS X, Python (I've tried both 2.7 and 3.3), and Django 1.6.
This topic is addressed on many webpages, both in SO and elsewhere, and over a period of many years (one solution specifically uses MySQLdb 1.2.2, which was last modified in March 2007). Some of the posts seem to say they have it working, but when I try their solution, it doesn't work for me. On the other hand, one post from a few months ago flatly says it can't be done.
The heart of the problem seems to be installing a driver (whether MySQLdb or mysql-connector), and symptoms vary depending on which instructions you follow. Typical show-stoppers from the various attempted solutions have been "No module named 'MySQLdb'" and "Symbol not found: _mysql_affected_rows" when you finally try "python manage.py syncdb".
One wonders whether the very act of trying so many solutions has itself messed up my dev environment so that what would have worked with a clean slate won't work now. Yes, I've tried this both with and without virtualenv. I don't know whether virtualenv has gotten me closer or not, because I don't know how to recognize getting closer.
I happen to have OS X 10.7.5 (Lion) and MySQL 5.0 on my machine. Those are not the latest versions of either, but I don't know whether that matters and I'm reluctant to keep changing things. They work fine for other MySQL applications on my machine. I'll gladly upgrade either or both if a solution is available for later versions.
Does anyone actually have the configuration listed as the title of this post working, with either Python 2.7 or 3.3? If so, I'd be most grateful if you'd direct me to the solution.
UPDATE
I just wanted to let readers know that I eventually did get my app running with Python 3.3, Django 1.6, and sort-of MySQL. My app has been running smoothly for months.
I'm sorry, I don't have the time to recreate the many hours of steps and mis-steps I followed to get this working. I'll just outline the key points:
I started using Macs more than a decade ago, starting with PowerBooks, so my Mac has a lot of old stuff on it. The first thing I finally decided I had to do was to get rid of every copy of Python and Django; installers such as MacPorts and Fink; and any of the directories they like to put their installations into. Google was of course invaluable to me in learning how to do this, and all the other steps mentioned below.
I then started fresh (as much as I could give my Mac a fresh start) using Homebrew as my only command-line installer.
I also used virtualenv. I don't actually understand virtualenv very well, and again don't have the time to research it, but I've got it working and it does seem to be a good idea.
Well, within virtualenv, I also used pip, which I guess is also a command-line installer, but it seems to be part of the Homebrew/virtualenv methodology. Sorry I can't provide any expertise on this.
As I mentioned, the app sort-of worked with MySQL, but when I used Homebrew to uninstall MySQL, and install MariaDB instead, it started to work really well. As far as I can tell, Django, Sequel Pro, PyCharm's DB features, and other programs that think they're talking to MySQL can't tell the difference between MySQL and MariaDB. I also really like the MariaDB online documentation. Admittedly, "MariaDB" isn't a great name, but neither is "MySQL".
Bottom line: If someone tells you it's impossible to get Python3.3 and Django1.6 running with MySQL (or at least MariaDB) on a Mac, don't believe them. It can be done, it's just hard to do if your system has a lot of legacy files and apps that can get into conflict with what you're trying to do.
One more thing: When I started work on this project, I suspended my work on a GAE app I'd been making great progress on for over a year. Since I'll be going back to that project soon, I wanted to keep my GAE install up-to-date on my machine, but sadly, I can no longer run the GAE installer for updates. I get some error about not being able to find python2.5. Sigh. That's what I'll have to look forward to solving when I get back to working on that project.
You could try using the pure-python pymysql:
sudo easy_install pymysql
(Use pip if you have it installed.) Then, add this before execute_from_command_line in manage.py:
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
I feel your struggle. I went through the same thing and found the setup process very frustrating. I don't really know which instructions you follow on which website that is throwing exceptions. But I find that all these instructions are missing either one or two small prerequisites. For example, xcode and command-line tools needed to be installed before doing any pip install. For the connectors, if you are using mysql-python, you probably need to install python-devel. I used this instruction. You are probably right that with so many installation attempts your system is probably corrupt and you might need to re-install your osx and start clean, again. It's painful, but that's what I had to do to make it work. I hope your next attempt works.
Related
There probably isn't one "right answer" to this question. I'm interested in thoughts and opinions.
We have a couple hundred RHEL7/Centos7/Rocky8 nodes. Many of them have python modules installed via pip/pip3.
I've been searching for a best practices on routine/monthly patching these modules...so I far haven't found any. Obviously things installed with rpm/yum/dnf are pretty easy to deal with.
From the pip man page:
pip install --upgrade SomePackage
Great!
But how do you update all of them?
Sure. It is possible to do a "pip list/freeze" pipe that to awk...etc..
Surely, there's a better way. Ideally, one that captures things like "boto3 V1.2 replaced with boto3 V1.3"
Right now it feels like I'm the only one thinking about this. Maybe I am and it is stupid. I'm ok with that response as well (but please tell me why).
A common solution is to deploy the application code inside a Docker container - the container image contains its own version of Python and all the dependency modules, so you don't have to update each module on all the host machines individually. It also means that the combination of OS, Python and modules that you deploy can be tested and then "frozen" into an immutable image which is then deployed the same everywhere.
Right now it feels like I'm the only one thinking about this.
I realise the above answer is probably not helpful in your situation as you already have a fairly large system deployed... but it might help to explain why not many people are developing solutions to your problem!
I'm having issues with Python on my 2013 MacBook Air. It seems to be mostly related to pathing, looking for libs in the wrong location based on where the calling lib was installed. I'd like to remove Python from my system and start fresh.
The specific reason I'm asking is due to a virtualenv problem. I created an env with the no-site-packages flag, but when I start my app with foreman, I get an error telling me that Flask isn't available yet when I open a python shell and "import flask", it works fine.
I don't really care which version of Python, or where it's installed as long as everything is consistent. Could I get advisement on how to proceed?
To be clear, I don't think this is a Yosemite issue, just mentioning it as a potential variable.
I have been trying to graph with python for some time now. I want to use matplotlib, but have hit so many bumps in the road. Previously, numpy and matplotlib have been installed, but I am stuck with this error: ImportError: numpy.core.multiarray failed to import. I'm running Lion on Mac. I think I'm using Python 2.7. I have also tried full walkthroughs, such as this as well: http://penandpants.com/2012/02/24/install-python/. After several installation methods like pip and homebrew I am afraid that there's a lot of knotted things going on with python on my computer. And I really don't know how to untangle it.
I am reasonably knowledgeable with programming and algorithms, but I lack the know-how on how all the add-ons such as matplotlib that connect with python or how a text editor that can execute my code like Sublime Text 2 accesses them. So, as much as I would like to aid this asking-a-question process by letting you know what versions I am using, I don't really know how. Any guidance to how python connects to these things would be really appreciated :)
Ultimately, I wish to start from scratch with this whole mess, reinstalling python and then matplotlib from the ground up--but I'm not totally sure how. So, I guess my final question is how do I do that, or if that is just a wrong line of thinking how do I proceed if I want to graph some mathy things with python?
Sorry for the long winded question, I'll appreciate any help even a nudge in the right direction in learning how my computer organizes python on my computer!
Thanks!
I've had similar problems and the best solution I found was to use MacPorts for managing python and my installed modules. The things that I particularly like about using MacPorts for this are:
You can easily install multiple python versions (with modules separately installed for each installation)
You can select which python installation is the default (whether it is one installed by MacPorts or your OS X python installation).
Many MacPorts packages have optional variants so you can easily customize how they are installed (e.g., should numpy use the ATLAS library from MacPorts or from OS X) .
If you screw up your installation, you can easily wipe MacPorts from your system without worrying about breaking anything (almost everything installed by MacPorts is put under /opt).
I recently did a clean install of OS X Lion. I'm now running Django 1.2.5 on Python 2.6.6 using virtualenv. The MySQL version is 5.5.14 (installed via homebrew). When I run the test suite of one of my applications now, it is just insanely slow. Usually the whole test suite would take about 4-5 minutes. Now after that time it isn't even done with ~30%.
Anybody any ideas on how I could narrow down the bottleneck? Could it be the fresh install of MySQL is just configured bad? How would I benchmark MySQL best and what might be the issue with the (InnoDB) tables? Maybe I'm not the only one having these problems...
OK, so to answer my own question, I found out it was actually just bad default settings for the MySQL installation. I ran over this script called MySQLTuner and it showed me some variables I should change. After following it's recommendations the tests finish in normal times again.
According to this TechCrunch article: Nine Things You Should Do After Installing OS X Lion, Lion is re-indexing your files. Leave it alone for a good few hours.
Following link may help >> http://www.stereoplex.com/blog/speeding-up-django-unit-test-runs-with-mysql
I config /etc/my.cnf with this suggestion, and Django runs fast!
[mysqld]
skip-sync-frm=OFF
I'm developing on Snow Leopard and going through the various "how tos" to get the MySQLdb package installed and working (uphill battle). Things are a mess and I'd like to regain confidence with a fresh, clean, as close to factory install of Python 2.6.
What folders should I clean out?
What should I run?
What symbolic links should I destroy or create?
One thing you should not do is try to remove or change any of the Apple-supplied python files or links: they are in /usr/bin and /System/Library/Frameworks/Python.framework. These are part of OS X and managed by Apple. It is fine to clean up any unnecessary packages you have installed for that Python. They are in /Library/Python. If you installed a python.org Python and want to remove it, most of the files are in /Library/Frameworks/Python.framework. See here for complete instructions on how to remove them. And anything you installed into /usr/local is fair game.
Using virtualenvs is a fine idea but it's slightly less important on OS X where the concept of framework builds makes it easier to support multiple Python versions than on some other platforms.
The bigger issue, especially trying to use MySQL with Python, is getting all of the necessary non-Python libraries installed and built properly which is non-trivial given the variety of options available on OS X. For instance, depending on which Python instance and which OS X level running, you may need 32-bit or 64-bit or, possibly, both versions of things like the MySQL client libraries and the MySQLdb adapter. For that reason, I highly recommend using a complete solution from MacPorts. That way you have a good chance of getting all the right components built compatibly - and easily.
If necessary, install the base MacPorts as described on the MacPorts website then:
$ sudo port selfupdate
$ sudo port install py26-mysql
and that will pull in and build everything you need and make it available in /opt/local/bin. There are also plenty of other ports available, for instance:
$ sudo port install py26-virtualenv
Virtualenv might still work for you. Install it, then create virtual python environments with the --no-site-packages option. This won't clean up your base system, but should allow you to develop in pretty good isolation from the base system.
My experience doing development on MacOSX is that the directories for libraries and installation tools are just different enough to cause a lot of problems that you end up having to fix by hand. Eventually, your computer becomes a sketchy wasteland of files and folders duplicated all over the place in an effort to solve these problems. A lot of hand-tuned configuration files, too. The thought of getting my environment set up again from scratch gives me the chills.
Then, when it's time to deploy, you've got to do it over again in reverse (unless you're deploying to an XServe, which is unlikely).
Learn from my mistake: set up a Linux VM and do your development there. At least, run your development "server" there, even if you edit the code files on your Mac.
when doing an "port selfupdate", rsync timesout with rsync.macports.org. There are mirror sites available to use.