You can create a setup.py file at the outermost level. So your directory tree may look like this
|_project_name
|_codes
|_pre.py
|___init__.py
|_training
|_models.py
|___init__.py
|___init__.py
|_setup.py
Then in the setup.py do something like this
from distutils.core import setup
from setuptools import find_packages
requires = [
'six>=1.10.0',
]
if __name__ == "__main__":
setup(
name="project-name",
version="0.0.1",
packages=find_packages(),
author='Your Name',
author_email='[email protected]',
install_requires=requires,
description='The API to fetch data from different sources',
include_package_data=True,
)
And finally from the outermost directory use python setup.py install it will install your package and then you will be able to easily do from project_name.pre import * in models
Also consider using a virtualenv for this kind of things.
Hope this helps.
.pyextension, tryfrom pre import *.pyin import statementsys.paththings and use the import directly as you are doing for all other packages.trainingdirectory.