Python MySQLdb not importing

前端 未结 7 1600
无人及你
无人及你 2021-01-01 07:34

I have installed mysql server using

$ sudo apt-get install mysql-server

then I installed python-mysqldb using

$ sudo apt-ge         


        
相关标签:
7条回答
  • 2021-01-01 08:01

    You needed to install the module with pip pip install mysql-python

    0 讨论(0)
  • 2021-01-01 08:01

    Your code snippet is fine. So the problem lies with getting libraries to match up. Here are some tools to help track it down... but do post back to let us know how this worked out for you:

    $ python --version
    Python 2.6.6
    $ easy_install yolk
    $ yolk --list
    DecoratorTools  - 1.7          - active
    MySQL-python    - 1.2.2        - active
    ...
    
    $ pydoc -p 8080
    pydoc server ready at http://localhost:8080/
    
    $ python
    >>> import MySQLdb
    >>> help('modules')
    Please wait a moment while I gather a list of all available modules...    
    ArgImagePlugin      _bytesio            exceptions          pyexpat
    BaseHTTPServer      MspImagePlugin      cProfile            multifile
    MySQLdb  ....
    
    
    $ dpkg -L python-mysqldb
    /usr/lib/pyshared/python2.7/_mysql.so
    /usr/lib/pyshared/python2.6/_mysql.so
    

    Note the Ubuntu package installs mysql to several python versions.

    0 讨论(0)
  • 2021-01-01 08:01

    Why not try installing from the synaptic package manager instead. You could install python-mysqldb-dbg also.

    0 讨论(0)
  • 2021-01-01 08:04

    The package name is "MySQLdb". Case counts.

    0 讨论(0)
  • 2021-01-01 08:06

    Try these commands

    sudo apt-get install python-dev libmysqlclient-dev

    sudo pip install MySQL-python

    0 讨论(0)
  • 2021-01-01 08:13

    Python module names are case sensitive, even on case-insensitive file systems. Therefore "MySQLdb" and "mysqldb" are two different modules/packages. Use import MySQLdb instead.

    0 讨论(0)
提交回复
热议问题