tldr-pages / tldr-python-client

Python command-line client for tldr pages
https://pypi.org/project/tldr/
MIT License
596 stars 93 forks source link

ImportError: cannot import name 'cli' from 'tldr' #187

Closed gerazov closed 2 years ago

gerazov commented 2 years ago

Awesome tool :sunglasses:

I'm getting an import error on a fresh install - am I missing some dependencies?

$ sudo pip3 install tldr
Collecting tldr
  Using cached tldr-3.0.0-py3-none-any.whl (10 kB)
Requirement already satisfied: termcolor in /usr/lib/python3.10/site-packages (from tldr) (1.1.0)
Requirement already satisfied: shtab>=1.3.10 in /usr/lib/python3.10/site-packages (from tldr) (1.5.3)
Requirement already satisfied: colorama in /usr/lib/python3.10/site-packages (from tldr) (0.4.4)
Installing collected packages: tldr
Successfully installed tldr-3.0.0

$ tldr ls   
Traceback (most recent call last):
  File "/usr/bin/tldr", line 5, in <module>
    from tldr import cli
ImportError: cannot import name 'cli' from 'tldr' (/usr/bin/tldr.py)
MasterOdin commented 2 years ago

Do you have any other modules installed that might be using the tldr namespace? What's the output from doing pip3 list?

What are the contents of doing cat /usr/bin/tldr?

gerazov commented 2 years ago

I guess it's something with the environment - I can't reproduce on my other machine.

$ cat /usr/bin/tldr 
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from tldr import cli
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(cli())
And the pip3 list ```python $ pip3 list Package Version ------------------- ----------- anytree 2.8.0 apparmor 3.0.3 appdirs 1.4.4 application-utility 1.3.2 asn1crypto 1.4.0 Beaker 1.11.0 bottle 0.12.19 btrfsutil 5.15.1 CacheControl 0.12.6 ceph 1.0.0 ceph-volume 1.0.0 cephfs 2.0.0 cephfs-shell 0.0.1 certifi 2021.10.8 cffi 1.15.0 chardet 4.0.0 colorama 0.4.4 configobj 5.1.0.dev0 contextlib2 0.6.0.post1 cryptography 36.0.1 cupshelpers 1.0 distlib 0.3.3 distro 1.6.0 dnspython 2.1.0 docopt 0.6.2 docutils 0.16 fasteners 0.16.3 html5lib 1.1 idna 3.3 importlib-metadata 4.8.1 iotop 0.6 Jinja2 3.0.3 keyutils 0.6 LibAppArmor 3.0.3 lockfile 0.12.2 louis 3.20.0 lxml 4.6.5 Mako 1.1.6 Markdown 3.3.6 MarkupSafe 2.0.1 meson 0.60.3 more-itertools 8.10.0 msgpack 1.0.3 netsnmp-python 1.0a1 npyscreen 4.10.5 ordered-set 4.0.2 packaging 20.9 pacman-mirrors 4.23.2 pep517 0.12.0 Pillow 8.4.0 pip 20.3.4 ply 3.11 powerline-status 2.8.2 progress 1.6 psutil 5.8.0 pwquality 1.4.4 pyaml 21.8.3 pycairo 1.20.1 pycparser 2.21 pycups 2.0.1 pycurl 7.44.1 Pygments 2.10.0 PyGObject 3.42.0 PyJWT 2.2.0 pyOpenSSL 21.0.0 pyparsing 2.4.7 PyQt5 5.15.6 PyQt5-sip 12.9.0 pysmbc 1.0.23 python-dateutil 2.8.2 pytoml 0.1.21 PyYAML 5.4.1 rados 2.0.0 ranger-fm 1.9.3 rbd 2.0.0 reportlab 3.6.3 requests 2.26.0 resolvelib 0.5.5 retrying 1.3.3 rgw 2.0.0 setuptools 57.4.0 shiboken2 5.15.2 shtab 1.5.3 sip 4.19.25 six 1.16.0 smbus 1.1 team 1.0 termcolor 1.1.0 terminator 2.1.1 tldr 3.0.0 toml 0.10.2 tomli 1.2.2 tqdm 4.62.3 trash-cli 0.21.10.24 udiskie 2.4.0 urllib3 1.26.7 validate 5.1.0.dev0 webencodings 0.5.1 zipp 3.6.0 ```
MasterOdin commented 2 years ago

Does /usr/bin/python point at your python3 installation?

gerazov commented 2 years ago

It seems so:

$ which python
/usr/bin/python

$ ll /usr/bin/python              
lrwxrwxrwx 1 root root 7 дек 19 00:53 /usr/bin/python -> python3*

$ ll /usr/bin/python3 
lrwxrwxrwx 1 root root 10 дек 19 00:53 /usr/bin/python3 -> python3.10*
MasterOdin commented 2 years ago

I wonder if the * at the end of the symlink is messing anything up? Does /usr/bin/python --version print out 3.10? And if you do /usr/bin/python, can do you run import tldr at all in the repl?

Really, my only thought at this point on what the error could be is that /usr/bin/python that's referenced in the script above is divorced in some way from where pip3 has installed stuff.

gerazov commented 2 years ago

You're right - it does work in the REPL:

$ /usr/bin/python --version
Python 3.10.1

$ /usr/bin/python
Python 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tldr
>>> 
MasterOdin commented 2 years ago

Hm, what is /usr/bin/tldr.py? I think that might be the problem, where /usr/bin/tldr is then looking at /usr/bin/tldr.py to import from, but it's not the tldr that you installed via pip3, and so fails?

gerazov commented 2 years ago

Hmm, seems Python2 code in /usr/bin/tldr.py - removed it and now it works :+1:

Thanks :pray: