4

I'm looking to use Django on a shared host that's running an unknown version of CentOS. My main problem is trying to interface with a database. The server has MySQL installed, but not MySQL-python. I initially thought of suggesting running "yum install MySQL-python", but apparently the version of MySQL-python that's in the default repositories for CentOS is 1.2.1, and Django requires 1.2.1p2.

This requirement first started with Django 0.96. In the release notes, a deprecated interface called mysql_old was added for compatibility with older versions of MySQL-python. Last July this deprecated interface was unceremoniously dropped. The announcement of this change does not indicate a reason other than that it was old.

Is it possible to resurrect this old interface in Django 1.1? Have there been any changes to the database interface since then? What would be the danger in forcing Django to skip the version check and using 1.2.1? Is it possible to compile a later version on another machine and copy the files over to the host? What would I need to know in order to do that?

I also looked into SQLite, but CentOS ships with Python 2.4.3, and therefore would require the pysqlite2 extension, which (afaict) doesn't exist in the repository.

Everything could be solved by simply installing from source, but that's rather messy and I have a much smaller chance of convincing the company to do that than getting them to install something from the repository. I realize that it seems like I should just get a different host, but you'll have to trust me that I have my reasons to try to make this work.

note: I don't have any experience using CentOS or yum, so everything I've said about them is an informed guess. Please let me know if all I need to do is specify some settings or change repositories to get the updated versions of these packages. Thanks.

Kyle Cronin
  • 77,653
  • 43
  • 148
  • 164
  • I don't have permission to run yum I'm afraid, and I don't know if gcc is installed. Do you know of a way to compile MySQL-python on another machine and copy it to some spot in Python's sys.path on the host? – Kyle Cronin Apr 21 '09 at 23:13
  • If you have sufficient permissions to run yum, you should be able to compile any arbitrary mysql-python version you like by downloading it and using 'python setup.py install' (configuring if necessary for the locations of the mysql libraries). If gcc isn't installed, use yum to install it. If the wrong version of python (etc) is installed, use yum or gcc to replace the whole stack as necessary :-) Try 'cat /etc/issue' to find out which version of CentOS you have. – Jarret Hardie Apr 21 '09 at 23:16
  • Try typing gcc to see if it is installed – Jarret Hardie Apr 21 '09 at 23:17
  • I know this is going to sound really bad but all I have is FTP access. I've been able to execute a few shell commands from within Python scripts that I call by hitting their URLs, but it doesn't always work and I obviously can't do anything interactive. I just checked and I get an error when I try to invoke gcc so I don't think that it's installed. Curiously, I get the following message when trying to invoke "yum -v install MySQL-python": – Kyle Cronin Apr 21 '09 at 23:38
  • Loading "fastestmirror" plugin Loading "priorities" plugin Loaded plugins: fastestmirror, priorities Running "config" handler for "priorities" plugin Config time: 0.080 Running "init" handler for "fastestmirror" plugin Yum Version: 3.2.19 COMMAND: yum -v install MySQL-python Installroot: / Ext Commands: MySQL-python – Kyle Cronin Apr 21 '09 at 23:40
  • Oh boy... you are in a pickle :-) Points for honesty, and for the whole hacking with Python scripts and URLs thing. I feel for your predicament. I also think I missed the degree of your, um, constraints in the original post... sorry. – Jarret Hardie Apr 22 '09 at 00:40
  • In your shoes, I would try looking at the paths shown for the modules in sys.modules, and then using the os module to list those (and related) directories to see what's available that might not be imported by default; maybe it will reveal an API or DB-driver you didn't think was available. Failing that, can you downgrade the django install, even using FTP? Or contact the ISP to show that the django install they make available is inconsistent with their libraries? – Jarret Hardie Apr 22 '09 at 00:45
  • Actually I just have Django sitting beside my project and it seems to work OK, except for the no database access thing, so I think I could downgrade it if I need to. I'll give 0.96 with mysql_old a try, as well as moving mysql_old into Django 1.1/removing the version check. Thanks for trying though - I'm extremely frustrated at CentOS and the fact that their packages are YEARS out of date. – Kyle Cronin Apr 22 '09 at 01:17
  • 2
    I set up a VM, installed CentOS 5.3 (x86), then compiled the latest MySQL-python, copied it over to my host and it seems to work. However, I don't recommend this approach to anyone else unless they are, like I was, completely out of other options. – Kyle Cronin Apr 22 '09 at 03:14
  • I wanted to thank you for your attempts to help he, Jarret Hardie. I upvoted some of your top answers to give you some rep. – Kyle Cronin Apr 22 '09 at 03:16
  • Wow... creative solution. Sorry all my stuff ended up in the comments - I really thought my first comment would probably do it and didn't warrant a full answer. Thanks for the points though :-) – Jarret Hardie Apr 22 '09 at 12:24

2 Answers2

0

You can install centos' package python-setuptools and then using easy-install in it you can install the latest version of mysql-python like this

easy_install mysql-python
JMax
  • 26,109
  • 12
  • 69
  • 88
0

You can actually manually install the mysql-python adapters without compiling anything, if you can't get a recent package from the centos repos. Just download the mysql-python tarball (from the sourceforge site). In the tar ball are all kinds of setup scripts, readme's, etc. You can either run the ez_setup file, the setup file, or, just copy the MySQLdb directory to somewhere in your pythonpath. I think on centos, /usr/lib/python2.4/site-packages/ works.

Good luck!

Alex
  • 4,316
  • 2
  • 24
  • 28
  • I tried that at first, but MySQLdb needs a low-level driver that has to be compiled. However, compiling it in a VM and copying it over to my host seems to have done the trick. – Kyle Cronin Apr 22 '09 at 11:38