Config, Decouple error

Hey guys, I’m having a hard time with config and decouple.

This is my environment:

I have already tried Python versions from 3.8 to 3.11 on Streamlit.

Can someone help me?

[17:23:14] šŸ Python dependencies were installed from /mount/src/personal/balance-tracker/requirements.txt using pip.

Check if streamlit is installed

Streamlit is already installed

[17:23:16] šŸ“¦ Processed dependencies!


Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.





2023-09-04 17:23:33.279 Uncaught app exception

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/personal/balance-tracker/ethwalletbalance-streamlit.py", line 4, in <module>

    from decouple import config

ImportError: cannot import name 'config' from 'decouple' (/home/adminuser/venv/lib/python3.8/site-packages/decouple/__init__.py)

My requirements.txt looks like this:

requests
pandas
streamlit
decouple
apscheduler

I think you want python-decouple instead of decouple.

Hey @Goyo, thank you for the reply. It worked!

Now I’m having another error regarding config.

This is how I’m trying to access the config file:

import requests
import pandas as pd
import streamlit as st
from decouple import config
from apscheduler.schedulers.background import BackgroundScheduler

# Bitquery API key
bitquery_api_key = config("BITQUERY_API_KEY")

# Ethereum address you want to query
ethereum_address = "0xc99B3eF8eFD7eE8AC2F67b12862f9704dbD230FA"

this is my environment:

And this is my config file (I changed the API key for security reasons):

BITQUERY_API_KEY="xxxxxxxxxxxxxxxxx"

This is the error I’m getting now:

[18:12:10] šŸ“¦ Processed dependencies!


Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.





2023-09-04 18:12:50.215 Uncaught app exception

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/personal/balance-tracker/ethwalletbalance-streamlit.py", line 8, in <module>

    bitquery_api_key = config("BITQUERY_API_KEY")

  File "/home/adminuser/venv/lib/python3.9/site-packages/decouple.py", line 248, in __call__

    return self.config(*args, **kwargs)

  File "/home/adminuser/venv/lib/python3.9/site-packages/decouple.py", line 107, in __call__

    return self.get(*args, **kwargs)

  File "/home/adminuser/venv/lib/python3.9/site-packages/decouple.py", line 92, in get

    raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))

decouple.UndefinedValueError: BITQUERY_API_KEY not found. Declare it as envvar or define a default value.

Can you please help me?

The error message says it all. You need to declare BITQUERY_API_KEY as an environment variable or define a default value in the call to config().

It worked, thanks @Goyo!