ModuleNotFoundError: No module named 'openai.api_resources'

Hi all,

I’ve got my app working perfectly on my local machine, but when trying to host it on the cloud here on streamlit I’m getting: ModuleNotFoundError: No module named ‘openai.api_resources’
I get this error after selecting a few things that end up with a vector store being read.

I absolutely have openai included in my requirements.txt
This seems to be my one last hurdle before my app can go live and I’d appreciate your help!!

File “/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “/mount/src/guideline_gopher/app.py”, line 158, in
main()
File “/mount/src/guideline_gopher/app.py”, line 113, in main
guideline_gopher(store_name)
File “/mount/src/guideline_gopher/app.py”, line 49, in guideline_gopher
VectorStore = pickle.load(f)
^^^^^^^^^^^^^^
ModuleNotFoundError: No module named ‘openai.api_resources’

1 Like

As mentioned in the pypi page, the API has recently changed and your old code won’t work in recent versions without changes.

Installation

[!IMPORTANT] The SDK was rewritten in v1, which was released November 6th 2023. See the v1 migration guide, which includes scripts to automatically update your code.

Hi Goyo,
Thanks for the insight. I read through what you sent, but I am however at a loss as to why my code works just fine locally but fails when I try to run from streamlit cloud.
Locally I’m running it with Anaconda. Is it possible that Anaconda is running with the dependencies that I initialized it with like 3 weeks ago so the new openai updates are irrelevant?
If I knew the reason for why it’s running locally and not on the cloud surely I could fix the problem.
(I’m new to coding BTW)

Yes, I think the changes are more recent than that.

This was the solution. Although I’m not sure precisely what I did that got it working:

  • Mirrored the contents of the relevant packages from pip list command on Anaconda to my requirements.txt file
  • Deleted the app and r-launched with python 3.11, I was using 3.9

Now it’s working and onto another glitch I’m having now LOL

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.