Problen running python scripts outside of Eclipse
Question: All my python scripts work just fine when I run them in Eclipse, however when
I drage them over to the python.exe, they never work, the cmd opens and closes
immediately. If I try to do it with a command in cmd, so it doesn't close, I
get errors like:

**ImportErrror: No module named _Some Name_**

and the likes. How can I resolve this issue?


Answer: Your pathing is wrong. In eclipse right click on the project properties >
PyDev - PYTHONPATH or Project References. The source folders show all of the
pathing that eclipse automatically handles. It is likely that the module you
are trying to import is in the parent directory.

    
    
    Project
        src/
            my_module.py
    
        import_module.py
    

You may want to make a python package/library.

    
    
    Project
    
        bin/
            my_module.py
    
        lib_name/
            __init__.py
            import_module.py
            other_module.py
    

In this instance my_module.py has no clue where import_module.py is. It has to
know where the library is. I believe other_module.py as well as my_module.py
needs to have from lib_name import import_module if they are in a library.

my_module.py

    
    
    # Add the parent directory to the path
    CURRDIR = os.path.dirname(inspect.getfile(inspect.currentframe()))
    PARENTDIR = os.path.dirname(CURRDIR)
    sys.path.append(PARENTDIR)
    
    from lib_name import import_module
    
    import_module.do_something()
    

ADVANCED: The way I like to do things is to add a setup.py file which uses
setuptools. This file handles distributing your project library. It is
convenient if you are working on several related projects. You can use pip or
the setup.py commandline arguments to create a link to the library in your
site-packages python folder (The location for all of the installed python
libraries).

Terminal

    
    
    pip install -e existing/folder/that/has/setup.py
    

This adds a link to your in the easy_install.pth file to the directory
containing your library. It also adds some egg-link file in site-packages.
Then you don't really have to worry about pathing for that library just use
from lib_name import import_module.

