vaderSentiment Module Not Found Error

Summary

I have been trying to deploy an app but when triying to call a subprocess python file importing vaderSentiment library it throw me Module not found error.

Traceback (most recent call last):

article_transcript.py", line 2, in <module>
    from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
ModuleNotFoundError: No module named 'vaderSentiment'

Requirements file

pandas
streamlit
Pillow
vaderSentiment

Hi @Watchdog1, welcome to our forums! :wave:

I’m not too familiar with vaderSentiment but don’t you have to install NLTK too?

Best,
Charly

Hi @Charly_Wargnier I’ll try adding it to reqs file but not sure this worked completely fine locally. If this doesn’t work then?

you can try to use pipreqs to automatically generate your requirements.txt file and try to reboot the website to see if it works, watch this article here: How to Auto Generate requirements.txt (Dependencies) in Python - 3 examples

Hi @Melo04 I did try that but it didn’t work I don’t understand why is it throwing that error. I am sure I am making a silly mistake somewhere. Argh!

hmm you can try this and add to your requirements.txt, not sure if it works:
vaderSentiment @ git+(github repo link for vaderSentiment)

Can you pls share your github repo link

I suspect that is where your issue lies.

Hi @Goyo what else could I do then maybe write those functions in the other file in app.py itself? Let me know any other methods.

I don’t know what you are doing and why so I cannot answer that.

I do know that subprocesses are somewhat tricky and people often make mistakes, hence my suspicion.

@Goyo Hi thank you for your reply I am attaching a block for your reference to understand better maybe then you could help me solve it

Main App.py


st.set_page_config(
    page_title="Watchdog: Let's manage disinformation",
    page_icon='Scenes//LogoF-S.png',
    layout="wide",
    initial_sidebar_state="collapsed",
)


with st.container():
    menu, title = st.columns([3,1])

    with menu:
        selected2 = option_menu(
        menu_title=None,
        options=["Home", "Case Studies", "Analysis"],
        icons=["house", "book", "bar-chart-fill"],
        orientation="horizontal"
        )
        if selected2 == "Analysis":
            switch_page('Analysis')
        if selected2 == "Case Studies":
            switch_page('Casestudies')
    with title:
        pass
    
    st.title('Watchdog')
    st.write('Spreading Awareness')
    col1, col2, col3 = st.columns(3)

    with col1:
        st.subheader("Interactive Visuali")
        st.image("Scene.png")

    with col2:
        st.subheader("Nlling")
        st.image("Scenrytelling.png")

    with col3:
        st.subheader("R Data")
        st.image("Sceata.png")

    st.divider()
    # Create a placeholder for the video link
    if "url" not in st.session_state:
        st.session_state["url"] = ""   
    url = st.text_input("Enter the link to the video:", st.session_state["url"])


    if url:

        st.video(url)
        st.session_state["url"] = url
    if st.button("Let's Write a Story?"):
        try:
            subprocess.run(["python", "data_scrapping.py", url])
            st.write('We are analysing it in our newsroom')
            st.image('Scen.gif')
            time.sleep(5)
            switch_page('Analysis')
        except Exception as e:
            st.error(f"An error occurred: {e}")

data_scrapping.py

from j.article_transcript import ArticleTranscript
from j.youtube_transcript import YoutubeTranscript
#from j import youtube_transcript
#from j import article_transcript
import spreadsheet
import requests
import sys
from bs4 import BeautifulSoup
import youtube_transcript_api

# No change needed
def is_url_from_source(url):
    '''
    Checks if the url comes from a valid source (youtube or one of the article sources).
    Returns True if link contains 'youtube' or one of the valid sources. False otherwise.
    '''
    if 'youtube' in url and is_youtube_valid(url):
        return True
    
    else:
        article_sources = [source['source'] for source in article_transcript.SOURCES]
        for source in article_sources:
            if source in url:
                return True
    return False

def is_youtube_valid(url):
    reqs = requests.get(url)
    soup = BeautifulSoup(reqs.text, 'html.parser')

    if soup.find('meta', itemprop='name') is None:
        return False
    
    return True

article_transcript.py

from j.transcript import Transcript
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import requests
from bs4 import BeautifulSoup
from deep_translator import GoogleTranslator
import re

This is where the error shows while running the subprocess

article_transcript.py", line 2, in <module>
    from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
ModuleNotFoundError: No module named 'vaderSentiment'
subprocess.run(["python", "data_scrapping.py", url])

This will run the system python, not the python in your virtual environment. Use this instead:

subprocess.run([sys.executable, "data_scrapping.py", url])

@Goyo I tried this but when I host it online it gives me this error, I did import it.

name ‘sys’ is not defined

Is there an alternative way I could, run that file?

You need to import sys first.

Hi @Goyo Thank you so much for your help, this worked for me

import nltk
import sys
nltk.downloader.download('vader_lexicon')
1 Like