简体   繁体   English

pdoc 无法从其他模块导入该函数

[英]pdoc can't import the function from other module

i'm using python 2.7 and trying to gather documentation for our testing project using pdoc.我正在使用 python 2.7 并尝试使用 pdoc 为我们的测试项目收集文档。

pdoc is located here: D:\\dev\\Python27\\Scripts the regression project here: C:\\views\\md_LDB_RegressionTests_v03.1_laptop\\mts\\Tests\\LDB\\Regression\\Tests We are using proboscis for our tests and i'm trying to create html documentation for the separate group of tests, a separate python file in my case. pdoc 位于此处:D:\\dev\\Python27\\Scripts 回归项目位于此处:C:\\views\\md_LDB_RegressionTests_v03.1_laptop\\mts\\Tests\\LDB\\Regression\\Tests 我们正在使用 proboscis 进行测试,我正在尝试创建单独的一组测试的 html 文档,在我的例子中是一个单独的 python 文件。 I run such command:我运行这样的命令:

D:\dev\Python27\Scripts>python pdoc --html "C:\views\md_LDB_RegressionTests_v03.
1_laptop\mts\Tests\LDB\Regression\Tests\tests\check_system_management\check_capa
bilities_encoding_problems.py"

and get such answer:并得到这样的答案:

Traceback (most recent call last):
  File "pdoc", line 458, in <module>
    module = imp.load_source('__pdoc_file_module__', fp, f)
  File "C:\views\md_LDB_RegressionTests_v03.1_laptop\mts\Tests\LDB\Regression\Te
sts\tests\check_system_management\check_capabilities_encoding_problems.py", line
 4, in <module>
    from common.builders.system_request import default_create_system, create_cap
ability
ImportError: No module named common.builders.system_request

pdoc can't import the function from other modules in our regression... The structure of our project looks like this: pdoc在我们的regression中不能从其他模块中导入函数……我们的项目结构是这样的:

-Tests (C:\views\md_LDB_RegressionTests_v03.1_laptop\mts\Tests\LDB\Regression\Tests)
  -"common" package (with init file)
     -"builders" packege
        -system_request.py
  -"test" package
      -check_system_management package
         -check_capabilities_encoding_problems.py - this is the file i want to get documentation to

Of course there are lots of other packages but im not sure if it makes sense to describe all the structure now当然还有很多其他的包,但我不确定现在描述所有结构是否有意义

The import part of the check_capabilities_encoding_problems.py looks like this: check_capabilities_encoding_problems.py 的导入部分如下所示:

import urllib
from hamcrest import assert_that, all_of
from proboscis import test, before_class, after_class
from common.builders.system_request import default_create_system, create_capability
from common.entity.LDBChecks import LDBChecks

How can i point to pdoc where to look for the functions of other modules?我如何指向 pdoc 在哪里寻找其他模块的功能? thank you!谢谢你!

When using pdoc with my Spyder IDE, I use the following script to add a directory to pdoc path在 Spyder IDE 中使用 pdoc 时,我使用以下脚本将目录添加到 pdoc 路径

import pdoc
libpath = r'C:\Path\To\Module'
pdoc.import_path.append(libpath)
mod = pdoc.import_module('ModuleName')
doc = pdoc.Module(mod)
string = doc.html()

The pdoc.import_path is a list of currently used paths to look for your module; pdoc.import_path是当前用于查找模块的路径列表; pdoc.import_path equals sys.path in default. pdoc.import_path默认等于sys.path More info can be found in pdoc documentation.更多信息可以在pdoc文档中找到。

You can set PYTHONPATH env variable.您可以设置 PYTHONPATH 环境变量。 This is a path that say python where to find modules and packages by 3th party also you.这是一条说python在哪里可以找到第3方的模块和包的路径,也是你。

pydoc and pdoc read your code!!! pydoc 和 pdoc 阅读你的代码!!!

if you will run it from the same directory pdoc3 --html .如果您将从同一目录pdoc3 --html .运行它pdoc3 --html . or pydoc -w .pydoc -w . it should work if all the modules are in the same directory.如果所有模块都在同一目录中,它应该可以工作。 but if they are not:但如果不是:

make sure your main module in each directory has it sys full path append to it (to the same directory).确保每个目录中的主模块都将 sys 完整路径附加到它(到同一目录)。

sys.path.append("D:/Coding/project/....)

Relative path will not do the trick!相对路径不会成功!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM