I am trying to inspect the modules which are loaded from my script and their respective locations that is why I am trying to run
python -v mysrcipt.py
python -vv mysrcipt.py
Since I want to compare how the imports are loaded in two different scripts I want to redirect the verbose output which looks like this
# code object from '/usr/local/lib/python3.5/dist-packages/botocore/__pycache__/translate.cpython-35.pyc'
import 'botocore.translate' # <_frozen_importlib_external.SourceFileLoader object at 0x7f182affa748>
import 'botocore.handlers' # <_frozen_importlib_external.SourceFileLoader object at 0x7f182afe0a90>
# trying /usr/local/lib/python3.5/dist-packages/botocore/loaders.cpython-35m-x86_64-linux-gnu.so
# trying /usr/local/lib/python3.5/dist-packages/botocore/loaders.abi3.so
# trying /usr/local/lib/python3.5/dist-packages/botocore/loaders.so
# trying /usr/local/lib/python3.5/dist-packages/botocore/loaders.py
to a file. To do this I have tried
python -v mysrcipt.py > file.txt
python -v mysrcipt.py 2>&1 > file.txt
but the only thing that is written to the file are the logs of the script and not the verbose output regarding the imports.
How can I successfully redirect the imports related output to a file?