簡體   English   中英

如何在 pycharm 上導入 python 導師模塊?

[英]how to import the python tutor module on pycharm?

我正在使用 pycharm 使用 jupyter 筆記本,我無法導入允許詳細說明代碼執行的教程模塊。 我已經使用 pip 安裝導師安裝了該模塊,並且我已經調用了該模塊,但它返回如下內容:

ImportError                               Traceback (most recent call last)
Cell In [1], line 1
----> 1 from tutor import tutor
ImportError: cannot import name 'tutor' from 'tutor' (C:\Users\Gabriel Nunès\AppData\Local\Programs\Python\Python310\lib\site-packages\tutor\__init__.py)

如果有人有想法我很感興趣。 在此先感謝您的幫助。

這在很大程度上取決於tutor.py是如何實現的,以及在其__init__.py中如何定義導師模塊。

您確定這是導入它的正確方法而不僅僅是import tutor嗎?

為了更好地理解,查看tutor.py和它的__init__.py文件會很有幫助。

確保tutor.py和你的代碼文件在同一個文件夾中。

所以我檢查了,我們使用from tutor import tutor模塊。 然后我檢查了init .py,它是空的。 最后沒有tutor.py,但在搜索時我發現了一個名為tutor-script.py 的程序,其中包含以下內容:

#!"C:\Users\Gabriel Nunès\AppData\Local\Programs\Python\Python310\python.exe"
# EASY-INSTALL-ENTRY-SCRIPT: 'tutor==14.0.5','console_scripts','tutor'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'tutor==14.0.5'

try:
    from importlib.metadata import distribution
except ImportError:
    try:
        from importlib_metadata import distribution
    except ImportError:
        from pkg_resources import load_entry_point


def importlib_load_entry_point(spec, group, name):
    dist_name, _, _ = spec.partition('==')
    matches = (
        entry_point
        for entry_point in distribution(dist_name).entry_points
        if entry_point.group == group and entry_point.name == name
    )
    return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)


if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(load_entry_point('tutor==14.0.5', 'console_scripts', 'tutor')())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM