i'm learning modules in python 3.5. while can install , import packages using sudo pip install {package}, can't seem figure out how import own files.
i made test.py file single definition test. saved site-packages folder. can't seem import there. need understanding how import files.
i read online possibly using sys.path however, don't know how works.
if had following file structure:
/home/foo /home/foo/__init__.py /home/foo/bar.py
and wanted
import foo.bar foo.bar.somefn()
i first need do:
import sys sys.path.append("/home/foo")
notice init.py file, tells python submodules. don't need in instance, it's practice have:
however, since can repetitive, daunting , tough track, there lots of tools available setup code expands have dependencies , lots of files/folders. suggest read bit pip/disttools/easy-install , how make package 'setup.py'.
in addition, might want explore world of virtual environments , deployment solutions such buildout , anaconda. these keep code separated have several projects on go different needs, or different python builds , platform requirements. when comes time deploy code other machines, you'll have easier time replicating needs of project.
below series of articles info explaining packages, pip , setup.py starting work environment buildout. seems great series:
http://reinout.vanrees.org/weblog/tags/softwarereleasesseries.html
the official docs making setup.py:
Comments
Post a Comment