Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too much is imported by basic imports #10

Open
rob-smallshire opened this issue Jan 12, 2025 · 1 comment
Open

Too much is imported by basic imports #10

rob-smallshire opened this issue Jan 12, 2025 · 1 comment

Comments

@rob-smallshire
Copy link

If I perform a basic import such as,

from constituent_treelib import ConstituentTree, Language

many package which I don't need are imported. This is problematic for Python environments where tkinter is not available, such as when the Python interpreter is provisioned by pyenv or by uv, as is increasingly common. In fact, the above import fails in such environments with,

    from constituent_treelib import ConstituentTree, Language
/Users/rjs/.virtualenvs/demonstrable-codex/lib/python3.11/site-packages/constituent_treelib/__init__.py:3: in <module>
    from constituent_treelib.core import *
/Users/rjs/.virtualenvs/demonstrable-codex/lib/python3.11/site-packages/constituent_treelib/core.py:17: in <module>
    from .export import export_figure
/Users/rjs/.virtualenvs/demonstrable-codex/lib/python3.11/site-packages/constituent_treelib/export.py:8: in <module>
    from nltk.draw.tree import TreeView
/Users/rjs/.virtualenvs/demonstrable-codex/lib/python3.11/site-packages/nltk/draw/tree.py:12: in <module>
    from tkinter import IntVar, Menu, Tk
/Users/rjs/.pyenv/versions/3.11.4/lib/python3.11/tkinter/__init__.py:38: in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
E   ModuleNotFoundError: No module named '_tkinter'

I solved this, by modifying my installation of Constituent-TreeLib by removing from .export import export_figure from core.py. Now my program works, and I can use your otherwise excellent library successfully.

Please consider making default imports less onerous. We can import the visualisation code if we need it.

@Halvani
Copy link
Owner

Halvani commented Jan 13, 2025

Hello Rob,

thanks for pointing out this problem. Could you please open a pull request for this? Especially as your approach seems to have solved the problem.

Kind regards
Oren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants