I downloaded some code from a university website that calculates a metric evolutionary trees. I'm trying to run the program (called example.py) and the first line of the program is

from TreeGenerator import Tree_generator

I did not think this would be a problem because TreeGenerator.py is another file in the folder I downloaded. However, when I try to run the program it says that it cannot find the module TreeGenerator. I tried putting the folder in my path but that didn't work. I was wondering if there was any specific place in thy python folder that I have to put modules like that. Thanks!


Are these two files in exactly same directory or different subdirectories? Have you tried to put the library to site-packages directory. Is there setup.py file and have you read any included readme or instalk files?

You can use sys.path ...

# show the system path (aka. PYTHONPATH)
# as a list of directories that Python by default looks into
# the first item will be the working directory
# the directory  C:\\Python26\\lib\\site-packages
# might be the best to add your own modules to
# even though it is meant for packages only

import sys

"""possible output on Windows OS -->

This works on Windows or Unix, only the directory names will change.

Quick Fix

from sys import path

I can't think of anything.
If it is in the same directory, then that line should work.
Check your spelling of the module name?
Sometimes it is something simple.

do you have an __init__.py file in the module folders? Sometimes that might cause the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.