python-3.x 如何解决在运行pdoc(在Windows中)时未找到匹配规范的模块?

vfhzx4xs  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(124)

我试图从命令行在windows中运行pdoc文档中的简单演示脚本。使用python 3.11.4,并将virtualenv和PYTHONPATH设置为有问题的文件夹。

"""
A small `pdoc` example.
"""

class Dog:
    """ (dog) """
    name: str
    """The name of our dog."""
    friends: list["Dog"]
    """The friends of our dog."""

    def __init__(self, name: str):
        """Make a Dog without any friends (yet)."""
        self.name = name
        self.friends = []

    def bark(self, loud: bool = True):
        """*woof*"""

字符串

pdoc .\demo.py
我收到以下错误消息

Warn: pdoc cannot load 'pdoc' because a module with the same name is already imported in pdoc's Python process. pdoc will document the loaded module from C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\__init__.py instead.
Warn: Cannot find spec for pdoc.demo (from .\demo.py):
Traceback (most recent call last):
  File "C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\extract.py", line 62, in walk_specs
    raise ModuleNotFoundError(modname)
ModuleNotFoundError: pdoc.demo
 (C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\web.py:105)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Pythons\virtenvs\glogger11.4\Scripts\pdoc.exe\__main__.py", line 7, in <module>
  File "C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\__main__.py", line 207, in cli
    httpd = pdoc.web.DocServer((opts.host, opts.port or 8080), opts.modules)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\web.py", line 105, in __init__
    module_names = extract.walk_specs(specs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Pythons\virtenvs\glogger11.4\Lib\site-packages\pdoc\extract.py", line 85, in walk_specs
    raise ValueError(
ValueError: No modules found matching spec: .\demo.py
(

s5a0g9ez

s5a0g9ez1#

警告:pdoc无法加载“pdoc”,因为在pdoc的Python进程中已导入同名模块。pdoc将从C:\Pythons\virtenvs\glogger 11.4\Lib\site-packages\pdoc_init_.py记录加载的模块。
我认为这个错误信息泄露了它。您是否在名为pdoc的文件夹中运行pdoc,并且该文件夹中是否也有__init__.py?如果有__init__.py文件,pdoc会将当前目录视为一个模块。

相关问题