Search code examples
pythonmoduleinstallationpackage

Python: I can't import a module even though it's in site-packages


I'm following the tutorial "Think Python" and I'm supposed to install the package called swampy. I'm running python 2.7.3 although I also have python 3 installed. I extracted the package and placed it in site-packages:
C:\Python27\Lib\site-packages\swampy-2.1.1
C:\Python31\Lib\site-packages\swampy-2.1.1
But when i try to import a module from it within python:

import swampy.TurtleWorld

I just get no module named swampy.TurtleWorld.
I'd really appreciate it if someone could help me out, here's a link to the lesson if that helps:
http://www.greenteapress.com/thinkpython/html/thinkpython005.html


Solution

  • I extracted the package and placed it in site-packages:

    No, that's the wrong way of "installing" a package. Python packages come with a setup.py script that should be used to install them. Simply do:

    python setup.py install
    

    And the module will be installed correctly in the site-packages of the python interpreter you are using. If you want to install it for a specific python version use python2/python3 instead of python.