how to import the python tutor module on pycharm?

Viewed 35

I'm working on a jupyter notebook with pycharm and I can't import the tutorial module that allows to detail the code execution. I have installed the module with pip install tutor and I have called the module but it returns something like :

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)

If someone has an idea I'm interested. Thanks in advance for your help .

3 Answers

This highly depends on how tutor.py is implemented, as well as how the tutor module is defined in its __init__.py.

Are you sure this is the correct way to import it and not just import tutor?

For a better understanding it would be helpful to see tutor.py and it's __init__.py file.

Make sure tutor.py and your code file is in the same folder.

So I checked, and we import the module with from tutor import tutor. Then I checked the init.py and it is empty. Finally there is no tutor.py but while searching I found a program called tutor-script.py which contains this :

#!"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')())
Related