Importing python modules and text files I am new to blender, but not python, and have been asked to create a user-input dependent, stylized animation of a protein network I am working with:

text document >> information processed by python-script >> blender animates

So, if certain parameters in the network are changed, the differences in behavior can be observed visually as well.

Instead of coding in Blender's built-in Text Editor, I have been working in "pycharm". However, when I attempt to run the program through blender, it will throw an error and inform me that all my custom modules cannot be found and imported, though they are all in the same directory. Same goes for all the text documents. The text files in particular are a problem as we are talking about thousands of data-points that can't be manually entered.

All modules and text files are saved in the same directory as the program's master runner.

I am working on a windows 7, 64 bit windows machine.

additional information

the errors:

 # import error: 
 no module named 'x'
 # filenotfounderror:
 [errno2] No such file or directory: 'y'


blender_file_directory: C:\Users\Henry\Documents\Blender\file.blend

python_files_directory: C:\Users\Henry\PycharmProjects\project_name\runner.py

# import of modules:
from module import *

# import of txt file:
numpy.loadtxt('gillespie.txt', unpack=False)


The script is called through blender's own SDK like so: 

filename = "C:/Users/Henry/PycharmProjects/project_name/runner.py"
exec(compile(open(filename).read(), filename, 'exec'))


Text files are stored in the same directory as python scripts, so importing them when running the script through python is no problem. Only when it's run through blender does it throw an error.
A more detailed example of the technique zeffi outlined is illustrated by the following example from http://web.purplefrog.com/~thoth/blender/python-cookbook/import-python.html

import bpy
import sys
import os

dir = os.path.dirname(bpy.data.filepath)
if not dir in sys.path:
    sys.path.append(dir )
    #print(sys.path)

import cityFunctions

# this next part forces a reload in case you edit the source after you first start the blender session
import imp
imp.reload(cityFunctions)

# this is optional and allows you to call the functions without specifying the package name
from cityFunctions import *