Python 3.x 斯芬克斯找不到熊猫

Python 3.x 斯芬克斯找不到熊猫,python-3.x,python-sphinx,autodoc,Python 3.x,Python Sphinx,Autodoc,我正在尝试使用sphinx记录一个Python类。我使用的是Python 3.9.2和sphinx build 3.5.2。我正在运行命令sphinx build-b html源代码build,将.rst文件转换为.html文件。我已经在代码套件中的其他类和函数上成功地执行了此配置,因此我知道它们的文件组织方式没有问题。当我运行命令时,我得到以下错误 Warning: autodoc: failed to import class 'ReadTextFileKeywords' from modu

我正在尝试使用sphinx记录一个Python类。我使用的是Python 3.9.2和sphinx build 3.5.2。我正在运行命令
sphinx build-b html源代码build
,将
.rst
文件转换为
.html
文件。我已经在代码套件中的其他类和函数上成功地执行了此配置,因此我知道它们的文件组织方式没有问题。当我运行命令时,我得到以下错误

Warning: autodoc: failed to import class 'ReadTextFileKeywords' from module 'read_files'; the following exception was raised: No module named pandas
我确实在全球和我的虚拟环境中加载了熊猫的最新版本。有人知道为什么它不能加载熊猫吗?我如何解决这个问题

作为参考,文件结构如下所示

core_utilities
  |_core_utilities
  |_docs
      |_sphinx
          |_Makefile
          |_build
          |   |_html files
          |_source
              |_index.rst
              |_Introduction.rst
              |_read_files.rst
              |_operating_system.rst
              |_conf.py
conf.py文件包含以下信息

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../../core_utilities'))

# -- Project information -----------------------------------------------------

project = 'Core Utilities'
copyright = '2021, Jonathan A. Webb'
author = 'Jonathan A. Webb'

# The full version, including alpha/beta/rc tags
release = '0.1.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc',
              'sphinx.ext.autosummary', 'sphinx.ext.githubpages']
autodoc_member_order = 'groupwise'
autodoc_default_flags = ['members', 'show-inheritance']
autosummary_generate = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'nature'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
索引文件的格式如下

.. Core Utilities documentation master file, created by
   sphinx-quickstart 
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Core Utilities's documentation!
==========================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   Introduction
   operating_system
   read_files


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
# Import packages here
import os
import sys
import numpy as np
import pandas as pd
from typing import List
import sqlite3
# ================================================================================
# ================================================================================
# Date:    Month Day, Year
# Purpose: Describe the purpose of functions of this file

# Source Code Metadata
__author__ = "Jonathan A. Webb"
__copyright__ = "Copyright 2021, Jon Webb Inc."
__version__ = "1.0"
# ================================================================================
# ================================================================================
# Insert Code here


class ReadTextFileKeywords:
    """
    A class to find keywords in a text file and the the variable(s)
    to the right of the key word.  This class must inherit the
    ``FileUtilities`` class


    :param file_name: The name of the file being read to include the
                      path-link

    For the purposes of demonstrating the use of this class, assume
    a text file titled ``test_file.txt`` with the following contents.


    .. code-block:: text

        sentence: This is a short sentence!
        float: 3.1415 # this is a float comment
        double: 3.141596235941 # this is a double comment
        String: test # this is a string comment
        Integer Value: 3 # This is an integer comment
        float list: 1.2 3.4 4.5 5.6 6.7
        double list: 1.12321 344.3454453 21.434553
        integer list: 1 2 3 4 5 6 7
    """
    def __init__(self, file_name: str):
        self.file_name = file_name
        if not os.path.isfile(file_name):
            sys.exit('{}{}{}'.format('FATAL ERROR: ', file_name, ' does not exist'))
当我从操作系统模块导入docstring时,Sphinx工作得很好,所以我知道这不是问题所在。尝试从read_files模块导入时失败。read_files.rst文件具有以下格式

**********
read_files
**********

The ``read_files`` module contains methods and classes that allow a user to read different
types of files in different ways.  Within the module a user will find functionality that 
allows them to read text files and csv files by columns and keywords.  This module
also contains functions to read sqlite databases, xml files, json files, yaml files, 
and html files

.. autoclass:: read_files.ReadTextFileKeywords
   :members:
它正在读取的类,包括文件,其格式如下

.. Core Utilities documentation master file, created by
   sphinx-quickstart 
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Core Utilities's documentation!
==========================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   Introduction
   operating_system
   read_files


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
# Import packages here
import os
import sys
import numpy as np
import pandas as pd
from typing import List
import sqlite3
# ================================================================================
# ================================================================================
# Date:    Month Day, Year
# Purpose: Describe the purpose of functions of this file

# Source Code Metadata
__author__ = "Jonathan A. Webb"
__copyright__ = "Copyright 2021, Jon Webb Inc."
__version__ = "1.0"
# ================================================================================
# ================================================================================
# Insert Code here


class ReadTextFileKeywords:
    """
    A class to find keywords in a text file and the the variable(s)
    to the right of the key word.  This class must inherit the
    ``FileUtilities`` class


    :param file_name: The name of the file being read to include the
                      path-link

    For the purposes of demonstrating the use of this class, assume
    a text file titled ``test_file.txt`` with the following contents.


    .. code-block:: text

        sentence: This is a short sentence!
        float: 3.1415 # this is a float comment
        double: 3.141596235941 # this is a double comment
        String: test # this is a string comment
        Integer Value: 3 # This is an integer comment
        float list: 1.2 3.4 4.5 5.6 6.7
        double list: 1.12321 344.3454453 21.434553
        integer list: 1 2 3 4 5 6 7
    """
    def __init__(self, file_name: str):
        self.file_name = file_name
        if not os.path.isfile(file_name):
            sys.exit('{}{}{}'.format('FATAL ERROR: ', file_name, ' does not exist'))

autodoc导入您的类,这意味着在模块
read_files
的顶部,您应该从pandas导入任何
,因为它在类
ReadTextFileKeywords
中使用。当您说“我有(…)个熊猫全局加载”时,您是否在模块中使用它而不在模块顶部写入导入?很有可能您在命令行上执行Sphinx时没有激活venv(与运行应用程序时相反),这就是Sphinx在venv中找不到熊猫的原因。(尝试激活venv并再次运行Sphinx,应该可以工作。)当我从CLI运行命令时,venv被激活,但它找不到它。您的问题没有,我们看不到类、导入、
.rst
或配置文件。where
where
在运行Sphinx的CMD上找到库了吗?如果是这样,问题在于错误消息中提到的classe/module/autodoc。我刚刚更新了问题,以包含更多相关的详细信息。我不知道您的隐私问题是什么,但我强烈建议编辑您的姓名并提高costum mod标志,以便对编辑历史记录进行清理。