Issue with downloading Text Blob corpora while deploying

Hi,

I am building a basic sentiment analyzer that uses textblob as one of its dependencies

Now the issue is, it requires

python -m textblob.download_corpora

To download textblob corpora.
Running locally is not an issue since I can easily do that in the terminal but how do I run this command while deploying[on streamlit free tier]?

I tried adding

python -m textblob.download_corpora

to requirements.txt but it doesn’t seem to work.

[
In case this is helpful:
I use pip for installation
Am using venv for python virtual environment
]

hi @Jayant_Taneja, welcome to the Streamlit community!

I suspect you could do something like this article describes about running a subprocess:

In that case, you’d want to use one of the caching functions in Streamlit to ensure you don’t continue to download the dependencies every time the Streamlit app re-runs.

Best,
Randy

Hi Randy,

Sorry for the late reply. I checked out the approach that you mentioned and it seems to be a viable one.

I tried this “hack” though and now it seems to be working fine.

  • First I created a file “corpora.py” with the following code:
import subprocess
cmd = ['python3','-m','textblob.download_corpora']
subprocess.run(cmd)
print("Working")
  • The cmd command is the exact same command that is used to download the corpora via terminal

  • Next I imported this module into main

import corpora

Though this is working fine , I’m not sure if this is suitable for production grade apps since I’m no expert :sweat_smile:

Anyway, Thanks again for your reply! Hope you had a wonderful holiday!
Cheers!