Search code examples
pythonpython-3.xpackagedependency-managementpython-poetry

Poetry add <package> returns AttributeError


I am trying to create a Python package using poetry. I haven't been able to replicate the steps described in documentation. When I try to add a dependancy, e.g.

poetry add pendulum

I get

jan@jan-XPS-13-9380:~/Documents/Simosol/tmp/poetry-test$ poetry add pendulum
Using version ^2.1.2 for pendulum

Updating dependencies
Resolving dependencies... (1.0s)

  AttributeError

  __enter__

  at ~/.local/lib/python3.6/site-packages/poetry/utils/helpers.py:98 in download_file
       94│     url, dest, session=None, chunk_size=1024
       95│ ):  # type: (str, str, Optional[requests.Session], int) -> None
       96│     get = requests.get if not session else session.get
       97│ 
    →  98│     with get(url, stream=True) as response:
       99│         response.raise_for_status()
      100│ 
      101│         with open(dest, "wb") as f:
      102│             for chunk in response.iter_content(chunk_size=chunk_size):

This happens with every package I've tried (pandas, geopandas, numpy, shapely). I don't understand much what is the problem and I haven't found any similar questions on GitHub or here.

Question: What is causing this error and how can I fix it?

I use Ubuntu 18.04, Python 3.6.9


Solution

  • In the end, what worked for me was to reinstall poetry as described in the docs:

    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
    

    instead of

    python3 -m pip install poetry