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
Related
I'm using a python executable in a virtual environment. I tried doing the whole codesign thing as described here, including creating the certificate, etc. The command worked, but the result stayed the same. I think it used to work on previous versions of OS X, but I currently use the most recent El Capitan version (10.11.6) and it's not working anymore. Any ideas on how to fix it?
EDIT: I did see this solution, but since my python is in a virtual environment, I'm not sure it applies, unless you guys say otherwise...
EDIT 2: I tried the solution above, didn't work. I should mention that I am codesigning the python executable in the virtualenv.
EDIT 3: The thing that ended up working for me was upgrading flask to the current version, (using pip install flask --upgarde), and running the app with export FLASK_APP=app.py; flask run instead of with python app.py. When you run the app with flask run, the annoying dialog box doesn't pop up anymore. No codesigning needed to my knowledge. Hope this helps someone.
Why is that happening?
So the python executables in El Capitan spawns .../Python.framework/Versions/2.7/Resources/Python.app + some extra magic. The problem is that the framework bundle doesn't have its own signature, and it uses signatures of parent application binaries.
How to check?
The first thing to check after installing applications from non-Apple-maintained-source-that-might-steal-your-soul, is to check if the application you are installing is restricted:
ls -lO /System/Library/Frameworks/Python.framework/Versions/2.7/
csrutil status
If it is restricted it cannot be removed (even with root) as long as SIP is enabled.
What to do?
So you have several different options you must try:
Pre-Option 0 - I think you are doing it already: I am not sure how you are maintaining your virtual environments, so just confirm you are going through the process, like here.
Option 1 - safe, but might not work: Use brew to maintain your executables and pip to maintain your packages. That usually solves the problem immediately, but I am not sure what is your case :)
Option 2 - dangerous, but will work: Check and Disable the SIP. Unless you work in an environment protected by a team of IT guys with years of security experience, I don't suggest it. This option WILL solve the issue, but you basically getting rid of one of the security layers... GL!
UPDATE 1
There is another option (not sure if you tried it though)
Option 1.5 - I have no idea if it will work: Try Option 1 (csrutil disable), reboot, go through the codesign process, reboot, and undo the Option 1 (csrutil enable). I have never tried it, but it doesn't mean you can't :))) Credit goes to this SO answer here
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.
I'm trying to decide on which architecture to choose for developing Django 1.0.x through Django 1.2.1. I've managed to get MySQL, MySQLdb, PIL, and Python 2.65 installed on Snow Leopard using x86 64-bit builds, but I'm curious as to whether or not there is a definitive answer to this question at the moment, and if so, why?
Thank you!
Michaux
Of course it's possible. Advisable? You didn't mention httpd and mod_wsgi, or some other WSGI container. Get one installed and it should be fine.
It certainly is possible: I do it every day.
Some tips:
use virtualenv to sandbox your python packages between projects.
use mod_passenger (via Passenger.prefpane) to make VirtualHosts easier to deal with.
You may need to fiddle a bit harder with things if you run stuff under mod_python, as I recall having to work hard to get a version compiled that worked with the version of apache that is installed by default, and the python I was using.
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.
I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:
"Stock" Apple Python
MacPython
Fink
MacPorts
roll-your-own-from-source
I'm still primarily developing for 2.5, so the stock Python is fine from a functionality standpoint. What I want to know is: why should I choose one over the other?
Update:
To clarify, I am looking for a discussion of the various options, not links to the documentation. I've marked this as a Community Wiki question, as I don't feel there is a "correct" answer. Thanks to everyone who has already commented for their insight.
One advantage I see in using the "stock" Python that's included with Mac OS X is that it makes deployment to other Macs a piece of cake. I don't know what your deployment scenario is, but for me this is important. My code has to run on any number of Macs at work, and I try to minimize the amount of work it takes to run my code on all of those systems.
I would highly recommend using MacPorts with Porticus for managing your Python installation. It takes a while to build everything, but the advantage is that whatever you build yourself will be built against the same libraries, so you won't have to futz around with statically linked shared objects, etc. if you want your Python stuff to work with Apache, PostgreSQL, etc.
If you choose to go this way, remember to install the python_select port and use it to make your system use the Python installed from MacPorts.
As an added bonus, MacPorts has packages for most main-stream Python eggs, so if you should be able to have MacPorts keep you up-to-date with the latest versions of all that stuff :)
Here's some helpful info to get you started. http://www.python.org/download/mac/
Depends what you are using python for. If you are using MacOS funitionality and things like PyObjC you are probably best of with MacPython or the python provided by Apple.
I use Python on my Mac mostly for development of server side applications which later will run on FreeBSD & Linux boxes. For that I have used fink python for a few years and ever since MacPorts python. With mac ports it is simple to add required c modules (like database driver etc). It's also easy to keep two python Versions (2.5 & 2.6 in my case) around.
I used "compile your own" python to test pre-3.0 python but generally I find managing dependencies to c modules painfull if done by hand.
Thanks to easy_install installing pure python modules is fast and easy for all the options mentioned above.
I was never very much an IDE person. For development I use command line subversion installed by MacPorts, Textmate and occasionaly Expandrive do directly access files on servers. I personally are very dependent on Bicyclerepairman for Textmade to handle my refactoring needs.
Others seem to be very happy with Eclipse & Pydev.
How about EPD from Enthought? Yes, it's large but it is a framework build and includes things like wxPython, vtk, numpy, scipy, and ipython built-in.
I recommend using Python Virtual environments, especially if you use a Timecapsule because Timecapsule will back everything up, except modules you added to Python!
Based on the number of bugs and omissions people have been encountering in Leopard python (just here on SO!), I couldn't recommend that version. e.g., see:
Why do I get wrong results for hmac in Python but not Perl?
Problems on select module on Python 2.5
I would choose MacPorts.
It does not eliminate your existing python supplied by Apple since it installs by default in /opt/local/bin (plays nice with it) and plus it is easy to download and install additional python modules (even binary modules that you need to compile!). I use Porticus GUI to maintain my MacPorts installed list of packages, including python.
In my windows environment I use Eclipse and PyDev, which works quite well together, even if it's a bit sparse. Apparently the exact same environment is available for the Mac as well, so I suggest downloading Eclipse and using the internal update software function to update PyDev with the URL http://pydev.sourceforge.net/updates/. To look further into PyDev, look here.
Apple's supplied python is quite old – my tiger install has 2.3.5. This may not be a problem for you, but you would be missing out on a lot. Also, there is a risk that Apple will update it. I'm not sure if moving from 2.3.5 to (say) 2.4 would cause code to break, but I guess it's possible. This happened to perl people recently: http://developers.slashdot.org/article.pl?sid=09/02/18/1435227
Macpython is a framework build (as is Apple's, I believe). To be honest, I'm not sure exactly what that means, but it's a prerequisite for some modules, in particular wxPython. If you get python from macports or fink, you will not be able to run wxPython (unless you run it through X11).
And guess what was forgotten by every answer here ... ActivePython.
No compilation required, even for third-party modules such as numpy, lxml, pyqt and thousands of others.
I recommend python (any python?) plus the ipython shell. My most recent experience with MacPython was MacPython 2.5, and I found IDLE frustrating to use as an editor. It's not very featureful, and its' very slow to scroll large quantities of output.