如何使用pydb将sys.path信息传递给DDD? (使用虚拟环境)

时间:2019-03-06 02:24:23

标签: python tensorflow virtualenv ddd-debugger

我正在看一本书,研究虚拟环境中的张量流的keras。
我的虚拟环境〜/ .venv2中已经安装了一些软件包。
在虚拟环境中(获取激活脚本后),当我在下面的脚本(tt.py)中运行

import sys
print sys.path

我明白了
(venv2)ckim @ chan-ubuntu:〜/ Tensorflow / chapter_10 $ python tt.py

['/home/ckim/Tensorflow/chapter_10', '/home/ckim/venv2/lib/python2.7', '/home/ckim/venv2/lib/python2.7/plat-x86_64-linux-gnu', '/home/ckim/venv2/lib/python2.7/lib-tk', '/home/ckim/venv2/lib/python2.7/lib-old', '/home/ckim/venv2/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/home/ckim/venv2/local/lib/python2.7/site-packages', '/home/ckim/venv2/lib/python2.7/site-packages', '/home/ckim/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']

我可以在上面的sys.path变量中看到包路径。 但是,当我使用pydb使用ddd运行代码时,会得到不同的结果。 (我将其启动ddd -pydb tt.py并在ddd中运行它)

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/ckim/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']

如您所见,我的〜/ venv2下的所有软件包路径均未列出。如何将这些路径传递给调试器?

[ADD]
我发现仅在程序开始时添加了正确的sys.path,就可以在虚拟环境中使用所有包含ddd的软件包。像下面

import sys
sys.path = ['/home/ckim/Tensorflow/chapter_10', '/home/ckim/venv2/lib/python2.7', '/home/ckim/venv2/lib/python2.7/plat-x86_64-linux-gnu', '/home/ckim/venv2/lib/python2.7/lib-tk', '/home/ckim/venv2/lib/python2.7/lib-old', '/home/ckim/venv2/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/home/ckim/venv2/local/lib/python2.7/site-packages', '/home/ckim/venv2/lib/python2.7/site-packages', '/home/ckim/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']

但是我仍然想知道是否还有一种更优雅的方法(无需触动原始来源)。

0 个答案:

没有答案