I’m trying to access functions from
run_perf.py
inaddMetrics.py
by
including this import statementfrom analysis import run_perf ... runtime = run_perf.calcMs()
I keep getting ModuleNotFoundError: No module named ‘analysis’ but don’t know what about my import is wrong.
That means that Python can’t fine the “analysis” package. Python looks
in sys.path:
from sys import path
print(repr(path))
/Users/cameron/lib/python:/Users/cameron/rc/python
which contains my personal code and tabhistory for interactive python
use.
based on your file tree:
File Structure:
appName/ âââ bin/ âââ appName/ â âââ __init__.py â âââ runner.py â âââ analysis/ â â âââ __init__.py â â âââ run_perf.py â â âââ mem_perf.py â âââ conversion/
[…]
You need to include /path/to/appName/appName in your $PYTHONPATH.
For testing purposes, do that by hand< example:
export PYTHONPATH=/path/to/appName/appName
For an appplication tree like the above, as installed, one typical
approach would be to have the executable in appName/bin be a small
wrapper script which figured that out from its own path, set
$PYTHONPATH, then executed Python on your real Python main programme. Or
alternatively to have the installation process wire the required path
into the wrapper script to avoid having it guess.
Cheers,
Cameron Simpson cs@cskk.id.au