tabreturn / thonny-py5mode

A py5 plug-in for Thonny
Do What The F*ck You Want To Public License
23 stars 8 forks source link

Maybe a py5 installation issue... #42

Closed villares closed 1 year ago

villares commented 1 year ago

As I was creating a VM for a student based on a Xubuntu OVA I had, installed via plugin, JDK download successful, but in the end, importing py5 failed.

I was able to work around this issue by uninstalling py5 and re-installing it from the Thonny package management shell with pip3 install py5[jupyter]. The reason for the [jupyter] is a hint at the error message.

So maybe this is not a thonny-py5mode plugin issue, but a py5 installation issue, I don't know.

CC @py5coding, please see if this is related to the Jupyter packages support separation.

import py5 in the REPL resulted in this:

Python 3.10.6 (/home/xubuntubox/apps/thonny/bin/python3.10)
>>> import py5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/py5/__init__.py", line 85, in <module>
    from py5_tools.magics import load_ipython_extension  # noqa
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/py5_tools/magics/__init__.py", line 22, in <module>
    from .drawing import DrawingMagics, DXFDrawingMagic
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/py5_tools/magics/drawing.py", line 27, in <module>
    from IPython.display import display, SVG, Image
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/IPython/__init__.py", line 52, in <module>
    from .core.application import Application
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/IPython/core/application.py", line 27, in <module>
    from IPython.core import release, crashhandler
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/IPython/core/ultratb.py", line 101, in <module>
    import stack_data
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/stack_data/__init__.py", line 1, in <module>
    from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, \
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/stack_data/core.py", line 19, in <module>
    from stack_data.utils import (
  File "/home/xubuntubox/.config/Thonny/plugins/lib/python3.10/site-packages/stack_data/utils.py", line 11, in <module>
    from asttokens import ASTText
ImportError: cannot import name 'ASTText' from 'asttokens' (/home/xubuntubox/apps/thonny/lib/python3.10/site-packages/asttokens/__init__.py)
>>> 
probabilityfilter commented 1 year ago

I am newbie when it comes to py5, have little Python experience but not at CS level. Introducing py5 and Thonny to my son. I enjoy your content on Twitter. I was able to follow the instructions here and install py5 via Thonny plugins and download JDK but when I run a sample code (from this repo), I get a similar error - cannot import name 'ASTText' from 'asttokens'. PS: I use a Windows laptop. Being a newbie, I might be approaching this 'error reporting' completely wrong! Let me know if there is something else I should be doing about this error:

Traceback (most recent call last): File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 52, in <module> main() File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 44, in main imported.run_code( File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 135, in run_code _run_code( File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 259, in _run_code _run_sketch(sketch_path, classpath, exit_if_error) File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 196, in _run_sketch import py5 File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5\__init__.py", line 84, in <module> from py5_tools.magics import load_ipython_extension # noqa File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\__init__.py", line 22, in <module> from .drawing import DrawingMagics, DXFDrawingMagic File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\drawing.py", line 27, in <module> from IPython.display import display, SVG, Image File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\__init__.py", line 51, in <module> from .core.application import Application File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\application.py", line 26, in <module> from IPython.core import release, crashhandler File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\crashhandler.py", line 27, in <module> from IPython.core import ultratb File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\ultratb.py", line 101, in <module> import stack_data File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\__init__.py", line 1, in <module> from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, \ File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\core.py", line 19, in <module> from stack_data.utils import ( File "C:\Users\aramamoorthy\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\utils.py", line 11, in <module> from asttokens import ASTText ImportError: cannot import name 'ASTText' from 'asttokens' (C:\Users\aramamoorthy\AppData\Local\Programs\Thonny\lib\site-packages\asttokens\__init__.py)

villares commented 1 year ago

import name 'ASTText' from 'asttokens'**. PS: I use a Windows laptop. Being a newbie, I might be approaching this 'error reporting' completely wrong! Let me know if there is something else I should be doing about this error:

Hi @probabilityfilter !

I think I had a student with the same error! I'm afraid I don't understand the problem yet, sorry.

Can you try, from the Thonny menu "shell", pip3 uninstall py5 and then pip3 install py5[jupyter]?

Can you try this "portable" Thonny? https://www.dropbox.com/s/3ue4cx3yf372teg/thonny-4-with-py5-windows-portable.zip?dl=0

Otherwise this VM: https://drive.google.com/file/d/1L_h0gv87TGhawc2uTPfPk5tAm-XzldI4/view

Let's see if @py5coding has an insight about this ASTtokens import issue!

probabilityfilter commented 1 year ago

Thanks for the response. Unfortunately I am at the very beginning levels of 'behind the scene' actions but given enough time I can 'google' my way through :-) I copy pasted the first line you gave me and this is what I get. I will look into the error when I get some time during the weekend: image

villares commented 1 year ago

Cheers @probabilityfilter !

image

Maybe pip will work, and pip3 will be the same (for me they are the same).

image

image

probabilityfilter commented 1 year ago

hmm, for some reason it is saying py5 is not installed!! image

I even changed the path where I run this image

villares commented 1 year ago

Can you try this "portable" Thonny? https://www.dropbox.com/s/3ue4cx3yf372teg/thonny-4-with-py5-windows-portable.zip?dl=0

hx2A commented 1 year ago

Hello @probabilityfilter ! I am the maintainer of py5. I must have missed the @ mention from @villares back in November. I am reading this now.

The Python library asttokens is used for parsing syntax trees and syntax highlighting. It is not used by py5 but it might be used by Jupyter Notebook and/or JupyterLab.

py5 and the related library py5jupyter has support for Jupyter Notebooks. The two libraries were split about 6 months ago but there was still some deprecated code in py5.

This morning I made a long-awaited improvement to py5 to remove the deprecated code and completely separate py5 from Jupyter. After the next release, it will be possible to install py5 without also installing IPython or Jupyter. This will benefit Thonny users as installs will be simpler. In my test environments, I see that asttokens is not importable in my environment with py5 but is importable in my environment with both py5 and py5jupyter.

So I may have inadvertently solved this problem because py5 will no longer import any IPython libraries and therefore will not import asttokens.

The problem you faced before seems to have been a versioning issue, where IPython was looking for a newer or older version of asttokens. It might have been possible to fix it by installing a specific version of asttokens. I am confused why this problem took place. Somehow there was a versioning incompatibility issue in your environment.

The next release will be in January, probably.

hx2A commented 1 year ago

If you want to test the fix, I uploaded dev packages to test.pypi.org:

https://test.pypi.org/project/py5/0.9.0.dev0/#files

Thonny provides an option to install a python library from a wheel file. Download the wheel file and install using that feature, or with the command like pip install ./py5-0.9.0.dev0-py3-none-any.whl. Don't install directly from test.pypi.org directly, that can get messy.

probabilityfilter commented 1 year ago

Awesome, thanks so much. This method worked! (download wheel file and run pip command from Thonny). Now I can restart teaching my son some cool Python code

hx2A commented 1 year ago

Great, I am glad it worked! I didn't realize what I was changing would resolve bugs but I am so glad it did.

That package I uploaded is for testing purposes. My goal is to do a release in January.

Have fun teaching your son Python!!

villares commented 1 year ago

Fixed! Let's close this :smile: