Wednesday, 17 October 2012

Raspberry Pi - Python - Installing modules

Anyway, I've been using python on my raspberry pi to create some small programs and I've got a little more advanced I wanted to use some open source modules written by others.  Most python modules will come with a setup program, setup.py, which when called should install the module in the right place and configure the environment.

However whenever I tried to do this, I was presented with the following error:

"No module named setuptools"

Some google searches and a read of the python.org website told be I was missing the python setup tools component distribute.

So the first step is to install distribute:

mkdir python-setuptools
cd python-setuptools
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

Then download whatever module you need and run the setup.py program using the command:

sudo python setup.py install

Then with a bit of luck, your module should be setup and ready to use.

6 comments:

  1. Thanks for this post! I'm getting a similar error. I need to install the twitter api, so I assume I write "sudo python setup.py twitter"?? However I get told that python cannot open setup.p. There is not setup.py in my directory so do I need to change to a different directory?

    Thanks

    ReplyDelete
    Replies
    1. Ok, im not really sure from your description what your problem is. What module are you trying to install? Have you followed the blog post and installed distribute? Any other info ?

      Delete
  2. Hi Martin,

    Im trying to install distribute but after downloading and I try to do "sudo python distribute_setup.py" it says: cant open file... ...no such file or directory. Anything you know how to get around?

    Thanks,

    Jacob

    ReplyDelete
    Replies
    1. Did you download the file using - "curl -O http://python-distribute.org/distribute_setup.py" - did it work? Or create an error?

      Delete
  3. Hi,

    I did ""curl -O http://python-distribute.org/distribute_setup.py" and got in return:

    "#!python
    """Bootstrap distribute installation

    If you want to use setuptools in your package's setup.py, just include this
    file in the same directory with it, and add this to the top of your setup.py::

    from distribute_setup import use_setuptools
    use_setuptools()

    If you want to require a specific version of setuptools, set a download
    mirror, or use an alternate download directory, you can do so by supplying
    the appropriate options to ``use_setuptools()``.

    This file can also be run as a script to install or upgrade setuptools.
    """
    import os
    import shutil
    import sys
    import time
    import fnmatch
    import tempfile
    import tarfile
    import optparse

    from distutils import log...."

    It continues with alot more commands and text. No warnings that I can see. According to http://python-distribute.org/ the file "curl -O http://python-distribute.org/distribute_setup.py" refers to has been changed in July 2013, could it be the method has changed since your guide was written?

    If i try to list the files in directory python-distribute after "downloading" no files are shown.

    Big big thanks Martin for replying to my call for help! Very green in the software programing world.

    Jacob

    ReplyDelete
  4. Hi again Martin,

    solved the problem with the info from http://www.raspberrypi.org/phpBB3/viewtopic.php?t=33125&p=284421 and just run "sudo apt-get install python-setuptools"

    Thanks again for your help!

    ReplyDelete

Note: only a member of this blog may post a comment.