微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

狮身人面像找不到熊猫

如何解决狮身人面像找不到熊猫

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

Warning: autodoc: Failed to import class 'ReadTextFileKeywords' from module 'read_files'; the following exception was raised: No module named pandas

我确实在我的虚拟环境中全局加载了最新版本的 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`

当我从 operating_system 模块导入文档字符串时,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:

它正在读取的类,包含文件的格式如下

# 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'))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。