简体   繁体   English

Pydoc找不到已安装的模块

[英]Pydoc not finding installed modules

I am trying to generate HTML documentation using pydoc.我正在尝试使用 pydoc 生成 HTML 文档。 The project is divided in several subfolders, all of them containing __init__.py files.该项目分为几个子文件夹,所有子文件夹都包含__init__.py文件。

The content of __init__.py in my main folder is as follows:我的主文件夹中__init__.py的内容如下:

import sys
sys.path.insert(1, '.')

I can run the application without any problems.我可以毫无问题地运行该应用程序。 Files within subfolders can see files in the main folder, and all imported modules run just fine.子文件夹中的文件可以看到主文件夹中的文件,并且所有导入的模块都运行良好。

However, pydoc is giving me problems.但是,pydoc 给我带来了问题。 If I try to use it on files within subfolders, they won't see the files in the main folder.如果我尝试在子文件夹中的文件上使用它,他们将看不到主文件夹中的文件。

Also, installed modules are not seen.此外,没有看到已安装的模块。 For example, running pydoc -w on my ftp_operations file (located in the main folder) says it cannot find Paramiko, which runs just fine in the application.例如,在我的 ftp_operations 文件(位于主文件夹中)上运行pydoc -w表示它找不到在应用程序中运行良好的 Paramiko。

I have seen some similar questions but most of the answers refer to adding the __init__.py files, which I already have.我见过一些类似的问题,但大多数答案都是指添加我已经拥有的__init__.py文件。 I tried pdoc3 as well, with the same results.我也尝试了 pdoc3,结果相同。 What am I doing wrong?我究竟做错了什么? I am using Python 3.7.我正在使用 Python 3.7。

Thanks in advance!提前致谢!

Are you using a virtual environment?你用的是虚拟环境吗? pydoc by default will call a system Python executable (which may be unable to locate your modules) even if the command is called from within a virtual environment.默认情况下, pydoc将调用系统 Python 可执行文件(可能无法找到您的模块),即使该命令是从虚拟环境中调用的。

If you wish to use a virtual environment to generate docs with pydoc, you need to call python -m pydoc [OPTIONS] to ensure that the correct python executable is called.如果您希望使用虚拟环境通过 pydoc 生成文档,则需要调用python -m pydoc [OPTIONS]以确保调用正确的python可执行文件。 Alternatively, you can edit the shebang line of the pydoc script to refer to your environment.或者,您可以编辑pydoc脚本的 shebang 行以引用您的环境。

For example, the pydoc script should look something like:例如, pydoc脚本应该类似于:

#!/some/system/path/bin/python3.7

import pydoc
if __name__ == '__main__':
    pydoc.cli()

and would be changed to look like:并将更改为:

#!/usr/bin/env python

import pydoc
if __name__ == '__main__':
    pydoc.cli()

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

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