3

Installing MySQLDb (Python module) without Internet Connection

Hi all,

I need to install MySQLDb on a SLES 11 Development Server. This Dev Server does not have access to the public internet due to corporate firewall policies. I was assuming this would merely be a nuisance which would force me to do source installations etc on things more easily installed otherwise. Instead, I have hit a wall, during my attempt to ultimately install and run Django with MySQL support.

I have downloaded and unzipped MySQL-python-1.2.4, and I am attempting to run its setup.py. However, any attempt to run setup.py, even just sudo python setup.py --help, reults in the following

Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz

And then of course the download fails.

I downloaded and installed the current version of the distribute module (0.7.3), via sudo python setup.py build install. I assumed this would keep mysql-python's setup.py from trying to download distribute. But that does not appear to matter. I did have a quick look at mysql-client's setup.py to see where the download was being forced. It appears that its setup.py does this:

from distribute_setup import use_setuptools
use_setuptools()

Which calls this:

def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
                   to_dir=os.curdir, download_delay=15, no_fake=True):
    # making sure we use the absolute path
    to_dir = os.path.abspath(to_dir)
    was_imported = 'pkg_resources' in sys.modules or \
        'setuptools' in sys.modules
    try:
        try:
            import pkg_resources
            if not hasattr(pkg_resources, '_distribute'):
                if not no_fake:
                    _fake_setuptools()
                raise ImportError
        except ImportError:
            return _do_download(version, download_base, to_dir, download_delay)

And this, the import of pkg_resources fails (I have reproduced this from the command line); and the exception handler tries a download, which of course fails.

My understanding is that distribute is deprecated anyway, and that setuptools should be used instead. I do have setuptools installed; but is the mysqldb module hardcoded to use distribute, and possibly a specific version of distribute, and that's my issue? To be honest at this point I'm a bit confused about modules, dependencies, etc in Python (I'm quite mediocre at Python).

Thanks all, Bean

3 Answers 3

1
  1. git clone https://github.com/PyMySQL/PyMySQL or download tarball. for mysqldb: https://github.com/farcepest/MySQLdb1
  2. untar it
  3. run sudo python setup.py install

That's all.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks ... but these look like instructions to install pymysql, not mysqldb. Since my goal is to run Django, and Django does not support pymysql, and since I followed groups.google.com/forum/#!topic/django-users/y-9CnQFMGtk et al to try and get Django working with pymysql but still have an ImportError, I'm afraid this answer is not 100% fit for my needs. Thank you though.
Also, I am still curious as to why the mysqldb setup.py attempts to download a version of distribute, despite 1. I already have installed the most recent distribute and 2. distribute has been obviated by setuptools and I have installed the most recent setuptools as well.
1

Guess it's too late, but for the sake of the future googlers...

I had the same problem. To solve it I had to comment these lines:

if not hasattr(pkg_resources, '_distribute'):
            if not no_fake:
                _fake_setuptools()
            raise ImportError

After this I was able to install MySQL-python via python setup.py install.

Comments

1

The answer to this question appears to be version dependent. MySQLDb version 1.2.5 (newest version as of this writing) and later do not require distribute so python setup.py install will work. Version 1.2.5 was released 01/2014 so this question is just that old.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.