简体   繁体   中英

Using MySQLdb on Python 2.5

I'm using Amazon AMI which uses yum to install packages. I'm currently using Python 2.5.

I have MySQLdb installed, when I run:

sudo yum install MySQL-Python

I get:

Package MySQL-python26-1.2.3-11.14.amzn1.x86_64 already installed and latest version

However when I try to import I get this error:

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

I think MySQLdb is trying to use Python 2.6 which is also installed (the python interpreter is showing 2.5). How do I fix this? Thanks!

The problem is that yum is linked with python 2.6. So when you install the package it goes to that python path and not the one you want. I don't either recommend changing the default python link to the one you want because you might break scripts using that version. What you can do is change your yum to point to the other python version:

This might work:

# vi /usr/bin/yum
FROM:
!/usr/bin/python
TO:
!/usr/bin/python2.5

And then run the command to download mysql db again.

If you use Django, for example, you can't do:

python manage.py runserver because this will link back to the default version. Instead you will have to use python2.5 manage.py runserver .

If you are going to use Django I recommend using PostgreSQL. MySQL has some serious limitations for queries. If you will not use Django, nevermind.

I hope it helps now :)

Source: How to switch between Python versions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM