Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running squad_to_dpr.py causes an error AttributeError: partially initialized module 'requests' has no attribute 'Response' (most likely due to a circular import) #4880

Closed
nhadziosma1 opened this issue May 10, 2023 · 0 comments · Fixed by #5099
Assignees
Labels
Contributions wanted! Looking for external contributions

Comments

@nhadziosma1
Copy link

I am trying to run the command:

python /home/my_user/.conda/envs/conda_env_py39/bin/python3/site-packages/haystack/utils/squad_to_dpr.py --squad_input_filename "path_to_my_input_data" --dpr_output_filename "path_where_data_would_be_saved"

in order to convert the format of my data into the format which is required by DPR. Unfortunately, I am getting the following error message:

Traceback (most recent call last):
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/haystack/utils/squad_to_dpr.py", line 70, in <module>
    from elasticsearch import Elasticsearch
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/elasticsearch/__init__.py", line 36, in <module>
    from .client import Elasticsearch
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/elasticsearch/client/__init__.py", line 23, in <module>
    from ..transport import Transport, TransportError
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/elasticsearch/transport.py", line 26, in <module>
    from .connection import Urllib3HttpConnection
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/elasticsearch/connection/__init__.py", line 19, in <module>
    from .http_requests import RequestsHttpConnection
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/elasticsearch/connection/http_requests.py", line 32, in <module>
    import requests
  File "/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/haystack/utils/requests.py", line 11, in <module>
    def request_with_retry(attempts: int = 3, status_codes: Optional[List[int]] = None, **kwargs) -> requests.Response:
AttributeError: partially initialized module 'requests' has no attribute 'Response' (most likely due to a circular import)

When I run the command print(sys.modules["haystack.utils.requests"]), I get as output:
<module 'haystack.utils.requests' from '/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/haystack/utils/requests.py'>

When I run the command print(sys.modules["requests.models"]), I get as output:
<module 'requests.models' from '/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/requests/models.py'>

I think that the problem is caused by the fact that inside the module haystack/utils/requests.py there is an import-statement, the import requests statement which should be importing a totally different package that is also called requests, but it imports itself (if that is even possible). The reason why I think that this is the case is because the package requests has a module called models.py, and in requests/models.py (which you can find on the following link: https://github.com/psf/requests/blob/ec78348c4b6292b1a38008fa31e51f7b6b2252dc/requests/models.py#L641) the Response class is implemented (which is mentioned in the error message).

Probably a very important piece of information is that when I display the content of sys.path, I get the following output:

['/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages/ray/thirdparty_files',
 '/home/my_user',
 '/home/my_user/.conda/envs/conda_env_py39/lib/python39.zip',
 '/home/my_user/.conda/envs/conda_env_py39/lib/python3.9',
 '/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/lib-dynload',
 '',
 '/home/my_user/.conda/envs/conda_env_py39/lib/python3.9/site-packages']

I guess that the executed import-statement (i.e. the line import requests from module haystack/utils/requests.py) looks first at the current directory and tries to import itself, rather than importing package requests from site-packages.

I would really appreciate your help with this matter, as I have no clue what else to try.

Additional information:

  1. I installed haystack package using shell-command pip install haystack[all], which installed the version 1.16.1 for me
  2. used OS is Linux
  3. used Python 3.9
  4. I am using a CPU (although it is not relevant for the issue)
  5. I am using a conda virtual environment (called conda_env_py39)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributions wanted! Looking for external contributions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants