How to install MySQLdb package? (ImportError: No module named setuptools)

后端 未结 11 1051
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-25 10:20

I am trying to install MySQLdb package. I found the source code here.

I did the following:

gunzip MySQL-python-1.2.3c1.tar.gz
tar xvf MySQL-python-1.         


        
相关标签:
11条回答
  • 2020-12-25 10:55

    When you need to install modules in Linux/Unix and you lack sudo / admin rights, one simple way around it is to use the user scheme installation, basically run

    "python setup.py install --user" from the command line in the folder of the module / library to be installed

    (see http://docs.python.org/install/index.html for further details)

    0 讨论(0)
  • 2020-12-25 10:56

    I am experiencing the same problem right now. According to this post you need to have a C Compiler or GCC. I'll try to fix the problem by installing C compiler. I'll inform you if it works (we'll I guess you don't need it anymore, but I'll post the result anyway) :)

    0 讨论(0)
  • 2020-12-25 11:00

    If MySQLdb's now distributed in a way that requires setuptools, your choices are either to download the latter (e.g. from here) or refactor MySQLdb's setup.py to bypass setuptools (maybe just importing setup and Extension from plain distutils instead might work, but you may also need to edit some of the setup_*.py files in the same directory).

    Depending on how your site's Python installation is configured, installing extensions for your own individual use without requiring sysadm rights may be hard, but it's never truly impossible if you have shell access. You'll need to tweak your Python's sys.path to start with a directory of your own that's your personal equivalent of the system-wide site pacages directory, e.g. by setting PYTHONPATH persistently in your own environment, and then manually place in said personal directory what normal installs would normally place in site-packages (and/or subdirectories thereof).

    0 讨论(0)
  • 2020-12-25 11:05
    #!/usr/bin/env python
    
    import os
    import sys
    from **distutils.core** import setup, Extension
    
    if sys.version_info < (2, 3):
        raise Error("Python-2.3 or newer is required")
    
    if os.name == "posix":
        from setup_posix import get_config
    else: # assume windows
        from setup_windows import get_config
    
    metadata, options = get_config()
    metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
    metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
    setup(**metadata)
    
    0 讨论(0)
  • 2020-12-25 11:13

    I resolved this issue on centos5.4 by running the following command to install setuptools

    yum install python-setuptools

    I hope that helps.

    0 讨论(0)
  • 2020-12-25 11:14

    Also, you can see the build dependencies in the file setup.cfg

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