Future-House / paper-qa

High accuracy RAG for answering questions from scientific documents with citations
Apache License 2.0
6.49k stars 623 forks source link

ZoteroDB import issue #57

Closed mdroidian closed 1 year ago

mdroidian commented 1 year ago

I'm trying to run https://github.com/whitead/paper-qa/blob/b20f4e9c72783735bf23cc1c43984c179dd5c731/README.md?plain=1#L172-L180

I've installed

pip install paper-qa
pip install pyzotero

I added a .env and tested it.

I get this error:

Traceback (most recent call last):
  File "C:\Users\mclic\AppData\Local\Programs\Python\Python39\lib\site-packages\paperqa\contrib\zotero.py", line 9, in <module>
    from pyzotero import zotero
  File "C:\Users\mclic\Desktop\Projects\dev\paper-qa\pyzotero.py", line 4, in <module>
    from paperqa.contrib import ZoteroDB
ImportError: cannot import name 'ZoteroDB' from partially initialized module 'paperqa.contrib' (most likely due to a circular import) (C:\Users\mclic\AppData\Local\Programs\Python\Python39\lib\site-packages\paperqa\contrib\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mclic\Desktop\Projects\dev\paper-qa\pyzotero.py", line 4, in <module>
    from paperqa.contrib import ZoteroDB
  File "C:\Users\mclic\AppData\Local\Programs\Python\Python39\lib\site-packages\paperqa\contrib\__init__.py", line 1, in <module>
    from .zotero import ZoteroDB
  File "C:\Users\mclic\AppData\Local\Programs\Python\Python39\lib\site-packages\paperqa\contrib\zotero.py", line 11, in <module>
    raise ImportError("Please install pyzotero: `pip install pyzotero`")
ImportError: Please install pyzotero: `pip install pyzotero`

Any ideas what I should try next? šŸ˜€

mdroidian commented 1 year ago

I've also tried

import dotenv
dotenv.load_dotenv()

from paperqa import Docs
from paperqa.contrib import ZoteroDB

docs = Docs()
zotero = ZoteroDB(library_type="user")  # "group" if group library

for item in zotero.iterate(limit=20):
    if item.num_pages > 30:
        continue  # skip long papers
    docs.add(item.pdf, key=item.key)

Same error.

pip install paper-qa
pip install pyzotero

Both return Requirement already satisfied:

whitead commented 1 year ago

Hi @mdroidian can you tell me what version of paper-qa you're on?

mdroidian commented 1 year ago

1.1.0

whitead commented 1 year ago

@mdroidian can you upgrade and try again?

MilesCranmer commented 1 year ago

Hey @mdroidian, I can't reproduce the issue, this code works fine for me. Perhaps you installed pyzotero into a different env?

For the record, I'm using the following pyproject.toml (with poetry):

[tool.poetry]
name = "paperqa"
version = "0.1.1"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "paperqa"}]

[tool.poetry.dependencies]
python = ">=3.8.1,<3.12"
pytest = "^7.2.2"
pre-commit = "^3.2.2"
requests = "^2.28.2"
ipython = "^8.12.0"
jupyter = "^1.0.0"
ipykernel = "^6.22.0"
langchain = ">=0.0.98"
html2text = "^2020.1.16"
openai = ">=0.27.0"
pypdf = "^3.7.0"
faiss-cpu = "^1.7.3"
pycryptodome = "^3.17"
tiktoken = "^0.3.3"
pyzotero = "^1.5.5"
llama-cpp-python = "^0.1.32"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Cheers, Miles

mdroidian commented 1 year ago

On a different machine (Both Windows), I installed again and ran:

load_dotenv()

from paperqa.contrib import ZoteroDB

docs = paperqa.Docs()
zotero = ZoteroDB(library_type="user")  # "group" if group library

for item in zotero.iterate(limit=20):
    if item.num_pages > 30:
        continue  # skip long papers
    docs.add(item.pdf, key=item.key)

Error:

Traceback (most recent call last):
  File "C:\Users\Michael\Desktop\Projects\dev\paper-qa\paperqa.py", line 4, in <module>
    from paperqa.contrib import ZoteroDB
  File "C:\Users\Michael\Desktop\Projects\dev\paper-qa\paperqa.py", line 4, in <module>
    from paperqa.contrib import ZoteroDB
ModuleNotFoundError: No module named 'paperqa.contrib'; 'paperqa' is not a package

I tried

from dotenv import load_dotenv
load_dotenv()

from paperqa import Docs
from paperqa.contrib import ZoteroDB

docs = Docs()
zotero = ZoteroDB(library_type="user")  # "group" if group library

for item in zotero.iterate(limit=20):
    if item.num_pages > 30:
        continue  # skip long papers
    docs.add(item.pdf, key=item.key)

And got error:

Traceback (most recent call last):
  File "C:\Users\Michael\Desktop\Projects\dev\paper-qa\paperqa.py", line 4, in <module>
    from paperqa import Docs
  File "C:\Users\Michael\Desktop\Projects\dev\paper-qa\paperqa.py", line 4, in <module>
    from paperqa import Docs
ImportError: cannot import name 'Docs' from partially initialized module 'paperqa' (most likely due to a circular import) (C:\Users\Michael\Desktop\Projects\dev\paper-qa\paperqa.py)

Versions

paper-qa                  1.1.1
pyzotero                  1.5.5

I also tried on WSL2. Same errors.

I'm not very familiar with python dev workflows / environments. Here is what I did:

goldengrape commented 1 year ago

maybe try this, in order

  1. pip install --upgrade --force-reinstall pyzotero

  2. pip install --upgrade --force-reinstall paperqa

mdroidian commented 1 year ago

My file name was paperqa.py šŸ¤¦ā€ā™‚ļøšŸ˜ I believe that was causing the error. Renaming it to paper.py worked.

jonathanmc commented 4 months ago

Ahaha separately I had the same problem and just happened to peruse this thread. So, thanks for the assist!