Search code examples
python-3.xspotify

"OSError: Starting path not found" when importing spotifycharts


I get the following error when importing spotifycharts:

OSError: Starting path not found

When I do pip freeze it's listed.

Full error:

OSError                                   Traceback (most recent call last)
/var/folders/fm/ck9x_7l55y93t7gkxl93g_q40000gn/T/ipykernel_57786/3799758561.py in <module>
      1 import environs
----> 2 import spotifycharts as sc

/opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/__init__.py in <module>
      9 from tqdm import auto
     10 
---> 11 from spotifycharts import classes
     12 from spotifycharts import settings
     13 from spotifycharts import exceptions

/opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/classes.py in <module>
     10 
     11 import spotifycharts as sc
---> 12 from spotifycharts import settings
     13 from spotifycharts import exceptions
     14 from spotifycharts.logging import logger

/opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/settings.py in <module>
      1 import environs
      2 configuration = environs.Env()
----> 3 configuration.read_env('spotifycharts/configuration.env')
      4 
      5 

/opt/anaconda3/envs/python39/lib/python3.9/site-packages/environs/__init__.py in read_env(path, recurse, verbose, override)
    413             if not start_dir:  # Only a filename was given
    414                 start_dir = os.getcwd()
--> 415             for dirname in _walk_to_root(start_dir):
    416                 check_path = Path(dirname) / env_name
    417                 if check_path.exists():

/opt/anaconda3/envs/python39/lib/python3.9/site-packages/dotenv/main.py in _walk_to_root(path)
    244     """
    245     if not os.path.exists(path):
--> 246         raise IOError('Starting path not found')
    247 
    248     if os.path.isfile(path):

OSError: Starting path not found

How do I solve this?


Solution

  • Was able to find a workaround.

    1. Open the settings.py file located in /opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/ in above case.
    2. Add the full path to the read_env() method

    Change

    configuration.read_env('spotifycharts/configuration.env')
    

    to

    configuration.read_env('/opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/configuration.env')