MaartenGr / BERTopic

Leveraging BERT and c-TF-IDF to create easily interpretable topics.
https://maartengr.github.io/BERTopic/
MIT License
6.19k stars 765 forks source link

Incompatibility with Python 3.12.1 on Linux #2091

Open bcritt1 opened 4 months ago

bcritt1 commented 4 months ago

Have you searched existing issues? 🔎

Desribe the bug

Import works fine when I roll back to Python 3.9.0. Get the following error on 3.12.1. On CentOS.

System info: CentOS Linux release 7.9.2009 (Core) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora"

Error: /home/users/$USER/.local/lib/python3.12/site-packages/hdbscan/plots.py:448: SyntaxWarning: invalid escape sequence '\l' axis.set_ylabel('$\lambda$ value') /home/users/$USER/.local/lib/python3.12/site-packages/hdbscan/robust_single_linkage_.py:154: SyntaxWarning: invalid escape sequence '\{' """Perform robust single linkage clustering from a vector array Traceback (most recent call last): File "/home/groups/$USER/fd_export/extract_body.py", line 4, in <module> from bertopic import BERTopic File "/home/users/$USER/.local/lib/python3.12/site-packages/bertopic/__init__.py", line 1, in <module> from bertopic._bertopic import BERTopic File "/home/users/$USER/.local/lib/python3.12/site-packages/bertopic/_bertopic.py", line 59, in <module> import bertopic._save_utils as save_utils File "/home/users/$USER/.local/lib/python3.12/site-packages/bertopic/_save_utils.py", line 29, in <module> import torch File "/home/users/$USER/.local/lib/python3.12/site-packages/torch/__init__.py", line 562, in <module> for name in dir(_C): ^^ NameError: name '_C' is not defined

Reproduction

from bertopic import BERTopic

BERTopic Version

0.16.2

MaartenGr commented 4 months ago

Checking the actions workflow of a recent commit shows that it runs well on python 3.12.4. I would be surprised if it works on 3.12.4 but not on 3.12.1, but who knows?

It might also be that there is something with your environment since torch is giving some errors. Have you tried creating a completely fresh environment and re-installing python, torch, and BERTopic?

Also, doing a quick google search gives me something like this which could be related.

bcritt1 commented 4 months ago

It's an HPC environment, so python is being installed fresh each time. Torch is coming in with BERTopic; I'm not installing that separately. If python alone isn't the issue, my suspicion would be the interaction with Linux is.

Basically the workflow is loading Python 3.12.1 and then doing the import statement and that fails, then purging that python, loading 3.9.0, doing the import, and that succeeds. This is managed through lmodhttps://lmod.readthedocs.io/en/latest/index.html if that gives a better idea.

It works for me, so not urgent on my end: just wanted to give you an idea that it seemed like an issue existed.


From: Maarten Grootendorst @.> Sent: Friday, July 19, 2024 2:35 AM To: MaartenGr/BERTopic @.> Cc: Brad Rittenhouse @.>; Author @.> Subject: Re: [MaartenGr/BERTopic] Incompatibility with Python 3.12.1 on Linux (Issue #2091)

Checking the actions workflow of a recent commithttps://github.com/MaartenGr/BERTopic/actions/runs/9937377510/job/27447607894 shows that it runs well on python 3.12.4. I would be surprised if it works on 3.12.4 but not on 3.12.1, but who knows?

It might also be that there is something with your environment since torch is giving some errors. Have you tried creating a completely fresh environment and re-installing python, torch, and BERTopic?

Also, doing a quick google search gives me something like thishttps://stackoverflow.com/questions/54408973/name-c-is-not-defined-pytorchjupyter-notebook which could be related.

— Reply to this email directly, view it on GitHubhttps://github.com/MaartenGr/BERTopic/issues/2091#issuecomment-2238763047, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A5HDGP2NGTKN6UZ52BU7KNTZNDMXDAVCNFSM6AAAAABLDP35TKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZYG43DGMBUG4. You are receiving this because you authored the thread.Message ID: @.***>

MaartenGr commented 4 months ago

Thanks! Glad to hear that you managed to resolve the issue with Python 3.9.0 but it's a shame this still happens for you with Python 3.12.1.

I'll leave this issue open in case others have similar issues.