If all occurring directories are Python packages, i.e. they all contain __init__.py
, then you can use
from ..bar_dir import bar
If the directories aren’t Python packages, you can do this by messing around with sys.path
, but you shouldn’t.
More Related Contents:
- Expand Python Search Path to Other Source
- Why use sys.path.append(path) instead of sys.path.insert(1, path)?
- set pythonpath before import statements
- Does Python IDE have a module which imports math functions such as cos or sin? [closed]
- How can I safely create a nested directory?
- Relative imports for the billionth time
- How do you properly determine the current script directory?
- Relative paths in Python
- mkdir -p functionality in Python [duplicate]
- PyLint “Unable to import” error – how to set PYTHONPATH?
- adding directory to sys.path /PYTHONPATH
- pip freeze creates some weird path instead of the package version
- Open file in a relative location in Python
- Set up Python on Windows to not type “python” in cmd
- Python: Platform independent way to modify PATH environment variable
- Too many different Python versions on my system and causing problems
- Why do circular imports seemingly work further up in the call stack but then raise an ImportError further down?
- How to configure Atom to run Python3 scripts?
- How can I troubleshoot Python “Could not find platform independent libraries “
- How to reload a module’s function in Python?
- numpy.genfromtxt produces array of what looks like tuples, not a 2D array—why?
- Python importing a module from a parallel directory
- python subprocess Popen environment PATH?
- How to set working directory for projects in PyCharm?
- ModuleNotFoundError: No module named ‘…’
- How can I extract the folder path from file path in Python?
- Import python module NOT on path
- How to remove bad path characters in Python?
- Why not os.path.join use os.path.sep or os.sep?
- How to use to find files recursively?