Django manage.py syncdb throwing No module named MySQLdb

后端 未结 5 1002
花落未央
花落未央 2021-02-04 12:59

I am a newbie learning Python/Django...

Am using the following tutorial located here.

Created a mysite database in MySQL 5 running on Snow Leopard.

Edite

5条回答
  •  既然无缘
    2021-02-04 13:30

    sudo easy_install mysql-python
    

    will install the MySQLdb module to allow you to work with MySQL from Python, or, if you want to work with virtualenv (which you should),

    sudo easy_install virtualenv virtualenvwrapper
    export WORKON_HOME=$HOME/.virtualenvs
    export PIP_VIRTUALENV_BASE=$WORKON_HOME
    source /usr/local/bin/virtualenvwrapper_bashrc
    mkvirtualenv mysite
    pip install mysql-python django
    

    Will put you inside a virtualenv with a current install of django (you can specify which version, e.g. django==1.1.1) and the MySQLdb module installed. Using virtualenv will allow you to have separate environments for different projects so you can install different modules and even use different versions of those modules (or Python) for different projects. To leave you virtualenv just type the command

    deactivate
    

    or, to switch to the environment 'foo' type

    workon foo
    

    You should also, if you're going to be using virtualenv add these three lines to your ~/.bash_profile (on OS X, ~/.bashrc generally on Linux):

    export WORKON_HOME=$HOME/.virtualenvs # where virtualenvs should be created
    export PIP_VIRTUALENV_BASE=$WORKON_HOME # tells pip where to look for virtualenvs
    source /usr/local/bin/virtualenvwrapper_bashrc # bash completion and wrapper functions for virtualenv
    

提交回复
热议问题