pybliometrics-dev / pybliometrics

Python-based API-Wrapper to access Scopus
https://pybliometrics.readthedocs.io/en/stable/
Other
410 stars 128 forks source link

ImportError: cannot import name 'KEYS' #226

Closed raffaem closed 2 years ago

raffaem commented 2 years ago
Please enter your API Key(s), obtained from http://dev.elsevier.com/myapikey.html.  Separate multiple keys by comma:
XXXXXXXXXXXXXXXXXXX
API Keys are sufficient for most users.  If you have an InstToken, please enter the token now;otherwise just press Enter:

Configuration file successfully created at C:\Users\rdpclient\.pybliometrics\config.ini
For details see https://pybliometrics.rtfd.io/en/stable/configuration.html.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
C:\Users\RDPCLI~1\AppData\Local\Temp/ipykernel_17032/112220137.py in <module>
      1 fulldf = pd.DataFrame()
----> 2 sres = pybliometrics.scopus.ScopusSearch(query)
      3 print(f"Number of results: {len(sres.results)}")
      4 df = pd.DataFrame(sres.results)
      5 fulldf = fulldf.append(df)

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pybliometrics\scopus\scopus_search.py in __init__(self, query, refresh, view, verbose, download, integrity_fields, integrity_action, subscriber, **kwds)
    194         self._query = query
    195         self._view = view
--> 196         Search.__init__(self, query=query, api='ScopusSearch', count=count,
    197                         cursor=subscriber, download=download,
    198                         verbose=verbose, **kwds)

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pybliometrics\scopus\superclasses\search.py in __init__(self, query, api, count, cursor, download, verbose, **kwds)
     59 
     60         # Init
---> 61         Base.__init__(self, params=params, url=URLS[api], download=download,
     62                       api=api, verbose=verbose)
     63 

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pybliometrics\scopus\superclasses\base.py in __init__(self, params, url, api, download, verbose, *args, **kwds)
     57                 self._json = loads(fname.read_text())
     58         else:
---> 59             resp = get_content(url, api, params, *args, **kwds)
     60             header = resp.headers
     61             if search_request:

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pybliometrics\scopus\utils\get_content.py in get_content(url, api, params, **kwds)
     53     from simplejson import JSONDecodeError
     54 
---> 55     from pybliometrics.scopus.utils.startup import _throttling_params, KEYS
     56 
     57     # Set header, params and proxy

ImportError: cannot import name 'KEYS' from 'pybliometrics.scopus.utils.startup' (C:\Users\rdpclient\AppData\Local\Programs\Python\Python310\lib\site-packages\pybliometrics\scopus\utils\startup.py)
Michael-E-Rose commented 2 years ago

Which version are you using?

raffaem commented 2 years ago

Thanks for the fast answer

Which version are you using?

$ python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybliometrics
>>> print(pybliometrics.__version__)
3.1.0
raffaem commented 2 years ago

I'm pretty sure the issue is that the config.ini file is not in the same drive as the python script that uses pybliometrics.

I moved the Python script to the same drive of config.ini and it fixed the issue.

Or it may have been that the python script was on a network shared folder with UNC path.

Michael-E-Rose commented 2 years ago

I'm almost certain it's the latter. We had this issue too. Turned out to be two different home directories. You can check that with pybliometrics.scopus.CONFIG_FILE from different locations.

raffaem commented 2 years ago

so the gist is: don't put you python scripts in a network shared folder?

should we write that in the docs?

raffaem commented 2 years ago

Nada, looks like it's the exact same config file:

Microsoft Windows [Versione 10.0.19041.1348]

rdpclient@XXXXXXXX C:\Users\rdpclient
$ python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybliometrics
>>> pybliometrics.scopus.CONFIG_FILE
WindowsPath('C:/Users/rdpclient/.pybliometrics/config.ini')
>>> exit()

rdpclient@XXXXX C:\Users\rdpclient
$ pushd XXXXXX

rdpclient@XXXX Y:\
$ python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybliometrics
>>> pybliometrics.scopus.CONFIG_FILE
WindowsPath('C:/Users/rdpclient/.pybliometrics/config.ini')
Michael-E-Rose commented 2 years ago

Turned out I didn't fix this bug as I though previously. But now it is :)

Must have been frightening for first-time users to get this long traceback upon creation of the configuration file - even though it would work on the second attempt.