Importing modules from parent folder
It seems that the problem is not related to the module being in a parent directory or anything like that.
You need to add the directory that contains ptdraft
to PYTHONPATH
You said that import nib
worked with you, that probably means that you added ptdraft
itself (not its parent) to PYTHONPATH.
Import Script from a Parent Directory
You don't import scripts in Python you import modules. Some python modules are also scripts that you can run directly (they do some useful work at a module-level).
In general it is preferable to use absolute imports rather than relative imports.
toplevel_package/
├── __init__.py
├── moduleA.py
└── subpackage
├── __init__.py
└── moduleB.py
In moduleB
:
from toplevel_package import moduleA
If you'd like to run moduleB.py
as a script then make sure that parent directory for toplevel_package
is in your sys.path
.
Import module from parent directory
Since the main
directory is the root directory of your project, you should not include main
in your absolute import:
from conf import mysql
or with relative import, you can do:
from ..conf import mysql
How do i import a function from a file in a parent directory
in the python structure for import, you should use system layout I mean:
parent/
__init__.py
one/
__init__.py
two/
__init__.py
three/
__init__.py
so first of all use init file the simply use import
Related Topics
Import Win32API Error in Python 2.6
How to Remove Specific Tag/Sticker/Object from Images Using Opencv
Tkinter Grid_Forget Is Clearing the Frame
How to Efficiently Handle European Decimal Separators Using the Pandas Read_CSV Function
How Does Python's "Super" Do the Right Thing
How to Programmatically Set a Global (Module) Variable
Child Processes Created with Python Multiprocessing Module Won't Print
Python - Using the Multiply Operator to Create Copies of Objects in Lists
Populate a Pandas Sparsedataframe from a Scipy Sparse Matrix
Replace Invalid Values with None in Pandas Dataframe
Pythonic Way to Combine For-Loop and If-Statement
Why Do I Need to Deploy a "Default" App Before I Can Deploy Multiple Services in Gae
How to Extend an Array In-Place in Numpy
How to Efficiently Process a Numpy Array in Blocks Similar to Matlab's Blkproc (Blockproc) Function