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

Installed through pip3, Thonny can't import jedi #434

Closed
aivarannamaa opened this issue May 23, 2018 · 7 comments
Closed

Installed through pip3, Thonny can't import jedi #434

aivarannamaa opened this issue May 23, 2018 · 7 comments

Comments

@aivarannamaa
Copy link
Member

Original report by cefn (Bitbucket: cefn
GitHub: cefn
).


Hi there,

When I launch Thonny, it is throwing up a huge window with a traceback in a massive font which is unreadable as it wraps every line 8 times, and the lines continue off the bottom of the screen. I am assuming that what I see in the console is a replica of the error in the alert dialog.

I installed thonny on Ubuntu Bionic using...

pip3 install thonny

I learned from early launch errors that I needed to also install...

sudo apt install python3-tk

...then...

pip3 install jedi

However, even after apparently successfully installing Jedi I get the following result...

cefn-bionic-thinkpad:~$ thonny
INFO: Loading early plugins from ['/home/cefn/.local/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/home/cefn/.thonny/plugins/lib/python3.6/site-packages']
ERROR: Failed loading plugin 'thonny.plugins.goto_definition'
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 243, in _load_plugins_from_path
    m = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/plugins/goto_definition.py", line 2, in <module>
    from jedi import Script
ModuleNotFoundError: No module named 'jedi'
ERROR: Failed loading plugin 'thonny.plugins.highlight_names'
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 243, in _load_plugins_from_path
    m = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/plugins/highlight_names.py", line 1, in <module>
    from jedi import Script
ModuleNotFoundError: No module named 'jedi'
ERROR: Error when initializing backend
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 287, in _init_runner
    runner.start()
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/running.py", line 64, in start
    self.reset_backend()
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/running.py", line 424, in reset_backend
    self._proxy = backend_class(configuration_option)
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/running.py", line 593, in __init__
    self._start_new_process()
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/running.py", line 754, in _start_new_process
    my_env["JEDI_LOCATION"] = self._prepare_jedi()
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/running.py", line 701, in _prepare_jedi
    import jedi
ModuleNotFoundError: No module named 'jedi'
ERROR: Failed loading plugin 'thonny.plugins.goto_definition'
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 243, in _load_plugins_from_path
    m = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/plugins/goto_definition.py", line 2, in <module>
    from jedi import Script
ModuleNotFoundError: No module named 'jedi'
ERROR: Failed loading plugin 'thonny.plugins.highlight_names'
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 243, in _load_plugins_from_path
    m = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/plugins/highlight_names.py", line 1, in <module>
    from jedi import Script
ModuleNotFoundError: No module named 'jedi'
ERROR: Failed loading plugin 'thonny.plugins.locals_marker'
Traceback (most recent call last):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/workbench.py", line 245, in _load_plugins_from_path
    getattr(m, load_function_name)()
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/plugins/locals_marker.py", line 141, in load_plugin
    if jedi_utils.get_version_tuple() < (0, 9):
  File "/home/cefn/.local/lib/python3.6/site-packages/thonny/jedi_utils.py", line 73, in get_version_tuple
    import jedi
ModuleNotFoundError: No module named 'jedi'

This is even though I get the following in a console...

python3 -c "import jedi; print(hasattr(jedi, 'Script'))"
True

Any ideas?

@aivarannamaa
Copy link
Member Author

I'll dig into your stacktrace later, but did you know that on Bionic you can apt install thonny ? Remove the pip-installed variant first, though.

@aivarannamaa
Copy link
Member Author

Original comment by cefn (Bitbucket: cefn
GitHub: cefn
).


Thanks for the suggestion and clear guidance.

However, one of the reasons for looking into Thonny and Pip3 specifically is to benefit a project I am launching where users are expected to do python coding, and I am guiding them remotely. I am trying to minimise the number of steps involved, and the diversity across platforms by starting with pip3 and getting everything from there, such that the same instructions can be used for Linux, Mac and Windows.

I have even been speculating if I can use Thonny as a precursor to pip instead of installing python3. It seems to work well from the Thonny shell like...

import pip
pip.main("install pyserial".split())

...and even...

pip.main("install --upgrade pip".split())

...but it's just weird enough to be confusing for learners I think, compared to any other instructions they would see for using pip, and hard to see all the output, compared to a routine console launch of pip install.

I am certainly quite confused that in the stack trace above Thonny fails to import jedi which is directly importable from python3. Does it maintain some kind of walled-off site-packages into which jedi also needs to be installed?

@aivarannamaa
Copy link
Member Author

Does pip3 install jedi install jedi under system libs or under current user home?

I know that with pip3 install --user jedi Thonny wouldn't be able to find jedi, because it manipulates sys.path upon startup by removing user site-packages component and adding ~/.thonny/plugins/.../site-packages instead. Basically it redefines the location of user site-packages. This allows "Tools => Manage plug-ins" to use pip install --user for installing packages under ~/.thonny.

I agree that this is not the most elegant solution. Maybe it's better to leave user site-packages as it is and just acknowledge, that Thonny stuff may be located in 3 places (installation site, ~/.thonny and user site-packages).

Another option would be to keep the original user site-packages in sys.path (after ~/.thonn/plugins/.../site-packages) ...

@aivarannamaa
Copy link
Member Author

I could also import all Thonny deps before this path manipulation. You can test it by putting import jedi as first line into .../thonny/__init__.py.

@aivarannamaa
Copy link
Member Author

Original comment by cefn (Bitbucket: cefn
GitHub: cefn
).


It seems it is related to using --user

But as per http://metadata.ftp-master.debian.org/changelogs/main/p/python-pip/python-pip_9.0.1-2_changelog this is not going away, and is likely to be increasingly adopted in the wider python community ( pypa/pip#1668 ) so worth getting a fix in place.

Until the --global flag is adopted via pypa/pip#4865 Debian users at least can use --system to override the default.

To fix this on my machine I first had to uninstall jedi and parso from my user directories (else a --system install is a no-op), then installed to system, by running...

pip3 uninstall jedi parso
sudo pip3 install --system jedi

I think it would make sense to keep the original user site-packages at the end of sys.path. If you were to add the user directories last, then presumably Thonny would continue to receive its own managed updates first and I don't have to advise my users to use sudo and --system. Raspbian is likely to be affected by this and they are core to your market I think.

@aivarannamaa
Copy link
Member Author

Fixed by dc1502c and 8b33bd3 .

See https://bitbucket.org/plas/thonny/pull-requests/13/changes-to-enable-thonny-to-launch-on/diff for discussion

Please test and reopen if not fixed!

@aivarannamaa
Copy link
Member Author

Original changes by Aivar Annamaa (Bitbucket: aivarannamaa
GitHub: aivarannamaa
).


  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant