Forums

ImportError: PyO3 modules may only be initialized once per interpreter process

I can load tiktoken locally with flask but once I try to use it on PythonAnywhere in production it errors with

Traceback (most recent call last):
File "/home/simonpalmer/ideally/flask_api.py", line 11, in <module>
import tiktoken
File "/home/simonpalmer/.local/lib/python3.10/site-packages/tiktoken/__init__.py", line 1, in <module>
from .core import Encoding as Encoding
File "/home/simonpalmer/.local/lib/python3.10/site-packages/tiktoken/core.py", line 9, in <module>
from tiktoken import _tiktoken
ImportError: PyO3 modules may only be initialized once per interpreter process

From what I can gather this is an issue with older versions of Py03. How do I fix this on PythonAnywhere?

Take a look at https://help.pythonanywhere.com/pages/InstallingNewModules

Was anyone able to fix this?

From the above, it looks like the you need to upgrade the Py03 module -- see the link provided by @fjl above.