"OSError: Starting path not found" when importing spotifycharts

"OSError: Starting path not found" when importing spotifycharts

导入时出现以下错误 spotifycharts:

OSError: Starting path not found

当我这样做时 pip freeze 它被列出了。

完整错误:

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

我该如何解决这个问题?

能够找到解决方法。

  1. 在上述情况下,打开位于 /opt/anaconda3/envs/python39/lib/python3.9/site-packages/spotifycharts/ 中的 settings.py 文件。
  2. 将完整路径添加到 read_env() 方法

改变

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

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