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

ImportError: cannot import name 'get_terminal_size' from 'click.termui' #377

Closed
7 tasks done
jmhummel opened this issue Mar 28, 2022 · 30 comments · Fixed by robusta-dev/robusta#378
Closed
7 tasks done
Labels
answered question Question or problem

Comments

@jmhummel
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer

Description

  • Install latest versions of typer (0.4.0) and click (8.1.0)
  • Run script with single line import typer
  • Import fails due to method get_terminal_size having been removed in click 8.1.0 (remove deprecated code pallets/click#2130)
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import typer
  File "/.venv/lib/python3.8/site-packages/typer/__init__.py", line 12, in <module>
    from click.termui import get_terminal_size as get_terminal_size
ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/.venv/lib/python3.8/site-packages/click/termui.py)

Operating System

Linux

Operating System Details

Ubunutu 20.04

Typer Version

0.4.0

Python Version

Python 3.8.10

Additional Context

No response

@jmhummel jmhummel added the question Question or problem label Mar 28, 2022
@browniebroke
Copy link

I think that'll be fixed in #375

@DimIsaev
Copy link

DimIsaev commented Mar 29, 2022

confirm the problem
appeared on import

import spacy

image

@fkoehlin
Copy link

fkoehlin commented Mar 29, 2022

Same here, also running into this exception with import spacy for spacy version 3.2.3. Reverting to spacy version 3.1.3 "solves" the problem for now.

CORRECTION:
It wasn't the spacy version... It's click (direct dependency from typer).
In both projects I have typer version 0.4.0 installed, the one which installed the newer click version 8.1.0 (and spacy 3.2.3) doesn't work, the older one (spacy 3.1.3) which installed click version 8.0.4 works.

tl;dr: Check your click version and force it <8.1.0.

paulgessinger added a commit to paulgessinger/histcmp that referenced this issue Mar 29, 2022
paulgessinger added a commit to paulgessinger/acts that referenced this issue Mar 29, 2022
Click had a breaking change in a minor version bump `8.0.4` -> `8.1.0` (see fastapi/typer#377) and
black `22.1.0` has an incompatibility with click `8.1.0` (bumping to
`22.3.0` should fix this)
@drorata
Copy link

drorata commented Mar 29, 2022

Same issue also with the minimal example from the docs on a clean Conda environment with Python 3.9.11. Actually, the error is raised when merely running import typer in the Python console:

python
Python 3.9.11 (main, Mar 28 2022, 05:06:49)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import typer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/drorata/anaconda3/envs/foo/lib/python3.9/site-packages/typer/__init__.py", line 12, in <module>
    from click.termui import get_terminal_size as get_terminal_size
ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/Users/drorata/anaconda3/envs/foo/lib/python3.9/site-packages/click/termui.py)

@Achuttarsing
Copy link

Exactly the same error for me with Python 3.7.13 :

Python 3.7.13 (default, Mar 18 2022, 17:46:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/ai/env/lib/python3.7/site-packages/typer/__init__.py", line 12, in <module>
    from click.termui import get_terminal_size as get_terminal_size
ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/var/www/ai/env/lib/python3.7/site-packages/click/termui.py)

@drorata
Copy link

drorata commented Mar 29, 2022

After downgrading Typer to 0.3.2 the problem is gone.

@DimIsaev
Copy link

After downgrading Click to 0.4.1 the problem is gone.

@Achuttarsing
Copy link

This temporary solution : explosion/spaCy#10564 (comment) works for me → pip install click==8.0.4

@KritsanaMike
Copy link

This temporary solution : explosion/spaCy#10564 (comment) works for me → pip install click==8.0.4

That correct !! I just fix the same your way. I downgrade click from 8.1.0 to 8.0.4 It's working now.

sinopeus pushed a commit to sinopeus/poetry-cookiecutter that referenced this issue Mar 29, 2022
This is a workaround for this Typer issue: fastapi/typer#377
sinopeus pushed a commit to sinopeus/poetry-cookiecutter that referenced this issue Mar 29, 2022
This is a workaround for this Typer issue: fastapi/typer#377
@jofegan
Copy link

jofegan commented Mar 29, 2022

I am seeing the same on a dependabot PR proposing to update the click version to 8.1
All my "import typer" statements fail with this error:

.tox/py3/lib/python3.8/site-packages/typer/__init__.py:12: in <module>
    from click.termui import get_terminal_size as get_terminal_size
E   ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/home/feganj/wip/.tox/py3/lib/python3.8/

@caetanovidal
Copy link

This temporary solution : explosion/spaCy#10564 (comment) works for me → pip install click==8.0.4

Thanks, I uninstall click and install again with 8.0.4 and works

kodiakhq bot pushed a commit to acts-project/acts that referenced this issue Mar 29, 2022
Click had a breaking change in a minor version bump `8.0.4` -> `8.1.0` (see fastapi/typer#377) and black `22.1.0` has an incompatibility with click `8.1.0` (bumping to
`22.3.0` should fix this)
TibsAtWork added a commit to Aiven-Labs/demo-opensearch-python that referenced this issue May 18, 2022
1. fastapi/typer#377 makes it necessary to
   update the version of typer to use a pinned version of click
   (that has the `get_terminal_size` function)
2. updated the other couple of main deoendencies a little
3. also need to specify requests
4. generated a new requirements.txt using `pip freeze`

After which `python search.py --help` works.
caufieldjh added a commit to ncbo/kg-bioportal that referenced this issue May 27, 2022
`click` >= 8.1 leads to this error during merge:
```
ImportError: cannot import name 'get_terminal_size' from 'click.termui'
```
See also fastapi/typer#377
aantn added a commit to robusta-dev/robusta that referenced this issue Jun 15, 2022
@michael-wise
Copy link

Apologies to add to noise. Reinforcing @drorata's comment that upgrading Typer to 0.4.1 resolved the issue and managed not to break any other dependencies in my gcp + pandas data pipeline.

gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 24, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 25, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 25, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 25, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 26, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 26, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377
gdoffe added a commit to cogip/mcu-firmware that referenced this issue Sep 26, 2022
Due to this error [1]:
  Traceback (most recent call last):
    File "/mcu-firmware/examples/sys_sysmon/sysmon-client.py", line 9, in <module>
      import typer
    File "/mcu-firmware/venv/lib/python3.10/site-packages/typer/__init__.py", line 12, in <module>
      from click.termui import get_terminal_size as get_terminal_size
  ImportError: cannot import name 'get_terminal_size' from 'click.termui' (/mcu-firmware/venv/lib/python3.10/site-packages/click/termui.py)

[1] fastapi/typer#377

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
epinnock added a commit to epinnock/chordz-backend that referenced this issue Sep 27, 2022
dimakarp1996 pushed a commit to dimakarp1996/dream that referenced this issue Nov 9, 2022
@github-actions
Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

dilyararimovna pushed a commit to deeppavlov/dream that referenced this issue Jan 24, 2023
* Update data.json

* Update scenario.py

* Update test.py

* Update tests.json

* Update requirements.txt

* Update skill.py

* Update requirements.txt

* Update test_no_annotations.json

* Update combined_classifier.json

* Codestyle using BLACK

* Update utils.py

* Update test.py

* Update test.py

* Update server.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update test.py

* Update server.py

* Update test.py

* Update test.py

* Update test.py

* codestyle

* Update utils.py

* Renamed topic_classification, deleted unnesessary string

* Speeded up the combined classifier

* Update Dockerfile

* New version of DeepPavlov

* Clean new combined - with fixed bug in checkout

* Update README.md

* Further speeded up multitask BERT model

* Update Dockerfile

* I have done my best to speed up the multitask inference.

* Update utils.py

* DeepPavlov version after several fixes. Also, new distil model ( not final, in training!)

* hh

* Tests fixed

* Update test.py

* codestyle

* Returned cuda cache

* Update Dockerfile

* Test change for memory profiling

* It should work much faster now

* It should work much faster now

* It should work much faster now

* Test editings to tackle test_dialog fail

* Update server.py

* Update combined_classifier.json

* codestyle

* Update Dockerfile

* Update combined_classifier.json

* Current test-passing version

* Changed factoid criteria & postprocess for cobot topics and intents

* Changed factoid criteria & postprocess for cobot topics and intents

* Minor test fix - updated "random skills" list

* codestyle

* codestyle

* Update factoid.py

* Update connector.py

* Utilize unified prob threshold in factoid skill. 

Before these changes, 2 different thresholds for factoid were set. One threshold 0.96 to turn the skill on, another 0.9 in the same skill. Given that the current model classifies question "where is montreal" as factoid with 0.55 probability, I have set the threshold 0.5 for both of these cases. And made the one threshold to use in both places to streamline the code

* Dilya's suggestion

https://github.com/deeppavlov/dream/pull/207/files#r1016588010

* Dilya's suggestion

https://github.com/deeppavlov/dream/pull/207/files#r1016569392

* Dilya's suggestions

* Dilya's suggestion

* Dilya's suggestion

* Dilya's comment

* Update Dockerfile

* Update Dockerfile

* Update combined_classifier.json

* Update README.md

* current changes

* Codestyle

* Added dependency to fix bug fastapi/typer#377

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update combined_classifier.json

* Update test.py

* Update server.py

* Update combined_classifier.json

* Update server.py

* Update test.py

* Passes skill tests now

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update server.py

* Fix bug

* Update Dockerfile

* Update dev.yml

* Update combined_classifier.json

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Added factoid threshold

* Update connector.py

* Update server.py

* Codestyle

* Codestyle

* Suggested changes

* current version

* Fixed sentence len

* Added setuptools dependency while numpy 1.18.0 not to fail on build

* Added setuptools dependency while numpy 1.18.0 not to fail on build

* Still facing bug numpy/numpy#22623 - restrict numpy version

* h

* Try to fix bug in test_dialog in utils/analyze_downloads.py while importing DeepPavlov - no module named ruamel. We might need to install it in dockerfile

* Update utils.py

* Update utils.py

* Threshold fixes as siggested by Dilya

* Cosmetic change

* Update combined_classifier.json

* fixed tests

* codestyle

* Update utils.py

* Suggested phrase fix

* Update dev.yml

* Remove empty requirements changes

* requirements fix

* Update connector.py

* Revert prev commit

* Names as in original

* added cache

* Update utils.py

* Update utils.py

* Update animals.py

* Update art.py

* Update books.py

* Update food.py

* Update gaming.py

* Update gaming.py

* Update music.py

* Update art.py

* Update travel.py

* Update science.py

* Update books.py

* Update food.py

* Update gaming.py

* Update gossip.py

* Update sport.py

* Update sport.py

* Update music.py

* Update movies.py

* codestyle

* codestyle

* Classname fix in tests

* suggested changes

* Update test.py

* Update test.py

* Update Dockerfile

* suggested changes

* Update Dockerfile

* Update combined_classifier.json

* Update Dockerfile

* Now we can infer for all postannotations

* Update Dockerfile

* Codestyle. Tests of combined (in old config) are passed 2x faster thanks to the improved caching

* Decreased inference time by another 25% without quality loss

* fixed tests

* codestyle

* New log format

* Update combined_classifier.json

* Changed singletask sentence length from 64 to 32 to speed model up by 15% and to make the compatibility with current DEV version

* Update server.py

* Remove MIDAS from pipeline

* Remove MIDAS from pipeline

* remove MIDAS from WAIT_HOSTS

* MIDAS from pipeline

* Убираю Мидас из WAIT_HOSTS и пайплайна

* Убираю Мидас из WAIT_HOSTS и пайплайна

* Not referring to midas annotations anymore and not waiting for midas

* All combined classification timeouts set to 2 sec

* Update dp_formatters.py

* Update dp_formatters.py

* Midas classification is a dict

* Get intents by function from common

* Update README.md

* codestyle

Co-authored-by: dimakarp1996 <dimakarp1996@github.com>
@RileyMShea
Copy link

Bot closed this but it appears to be unresolved.

@LeXofLeviafan
Copy link

LeXofLeviafan commented Oct 21, 2023

Here's the definition of the missing function at the time of removal:

def get_terminal_size() -> os.terminal_size:
    """Returns the current size of the terminal as tuple in the form
    ``(width, height)`` in columns and rows.

    .. deprecated:: 8.0
        Will be removed in Click 8.1. Use
        :func:`shutil.get_terminal_size` instead.
    """
    import shutil
    import warnings

    warnings.warn(
        "'click.get_terminal_size()' is deprecated and will be removed"
        " in Click 8.1. Use 'shutil.get_terminal_size()' instead.",
        DeprecationWarning,
        stacklevel=2,
    )
    return shutil.get_terminal_size()

I believe it should be trivial to fix this particular issue (and it wouldn't even break compatibility with click-8.0).

@LeXofLeviafan
Copy link

LeXofLeviafan commented Oct 21, 2023

…Waitaminute

According to release notes, this was fixed back in v0.4.1 over a year ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered question Question or problem
Projects
None yet