Skip to content

ImportError: cannot import name '_tiktoken' from partially initialized module 'tiktoken' #133

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

Closed
onlychenchen opened this issue May 19, 2023 · 2 comments

Comments

@onlychenchen
Copy link

onlychenchen commented May 19, 2023

I pulled the code and tried to run the use case:
"""
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
assert enc.decode(enc.encode("hello world")) == "hello world"
enc = tiktoken.encoding_for_model("gpt-4")
"""
but error:
File "D:\tiktoken-main\tiktoken\core.py", line 9, in
from tiktoken import _tiktoken
ImportError: cannot import name '_tiktoken' from partially initialized module 'tiktoken'(most likely due to a circular import)
how to fix this error? i need help, thanks!

@hauntsaninja
Copy link
Collaborator

Do you have some other file name tiktoken.py, e.g. like #106? There isn't enough information to reproduce this error.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2023
@akshat-g
Copy link

akshat-g commented Sep 4, 2023

@hauntsaninja - Actually, I am facing the same issue. I am using marvin - https://pypi.org/project/marvin/
It uses tiktoken as a dependency. So it installes tiktoken as well.
I am trying to use marvin on AWS lambda. When I invoke my lambda, error occurs:
cannot import name '_tiktoken' from partially initialized module 'tiktoken' (most likely due to a circular import) (/opt/python/lib/python3.9/site-packages/tiktoken/__init__.py)

It's here in tiktoken/core.py

from __future__ import annotations

import functools
from concurrent.futures import ThreadPoolExecutor
from typing import AbstractSet, Collection, Literal, NoReturn, Optional, Union

import regex

from tiktoken import _tiktoken

I have no file names as tiktoken.py so probably that is not causing the issue. Also I am using openai library as well, but not sure if that is causing the issue.

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

3 participants