简体   繁体   中英

pdoc3 ValueError: File or module 'xxx' not found if imported from other package

pdoc3 is a nice tool to generate documentation from code. In one of my projects, I got some exception. Wonder if it is caused by project structure. These are the folder structure of my two projects.

proj_A
  -src
    -automation
      -hl7ctl
        (has a definition of HL7CtlClient)

proj_B
  -src
    -automation
      -connctl
        -core.py
        -utility.py (uses HL7CtlClient)

In the utility.py of the proj_B, I have to import a class from project_A

from automation.hl7ctl import HL7CtlClient

This causes the following error by running pdoc3 at src folder in proj_B. The proj_A has been installed by using 'sudo pip3 install proje_A.gz'

automation.connctl.core No module named 'automation.hl7ctl' in pdoc3's code:

(Seehttps://github.com/pdoc3/pdoc/blob/master/pdoc/ init .py#L519 )

Traceback (most recent call last):
  File "/usr/local/bin/pdoc3", line 11, in <module>
    load_entry_point('pdoc3==0.5.5.dev13+g43f28dd.d20190427', 'console_scripts', 'pdoc3')()
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/cli.py", line 419, in main
    for module in args.modules]
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/cli.py", line 419, in <listcomp>
    for module in args.modules]
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/__init__.py", line 943, in __init__
    m, docfilter=docfilter, supermodule=self, context=self._context)
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/__init__.py", line 943, in __init__
    m, docfilter=docfilter, supermodule=self, context=self._context)
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/__init__.py", line 940, in __init__
    m = import_module(fullname)
  File "/usr/local/lib/python3.6/dist-packages/pdoc3-0.5.5.dev13+g43f28dd.d20190427-py3.6.egg/pdoc/__init__.py", line 520, in import_module
    raise ValueError('File or module {!r} not found'.format(module))
ValueError: File or module 'automation.connctl.core' not found

This is how I run pdoc3:

cd src
pdoc3 --overwrite --html --html-dir ../docs/APIs --template-dir ../docs/templates automation

There are __init__.py in automation and its subfolders but not 'src'.

The automation/ __init__.py has the following content:

__import__("pkg_resources").declare_namespace(__name__)

pydoc and pdoc read your code!!!

if you will run it from the same directory pdoc --html. or pydoc -w. it should work if all the modules are in the same directory. but if they are not:

make sure your modules in each directory has it sys full path appendded.

sys.path.append("D:/Coding/project/...the path the model is in")

Or, even better, you can make python to get the path:

path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(path)

Relative path will not do the trick!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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