Calysto / calysto_hy

Calysto Hy, a Jupyter kernel for Hy using MetaKernel
Other
103 stars 18 forks source link

ImportError: cannot import name '_hy_macros' #15

Open leetschau opened 5 years ago

leetschau commented 5 years ago

During the last step of the installation of calysto_hy, an error raised:

python -m calysto_hy install
Traceback (most recent call last):
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/site-packages/calysto_hy/__init__.py", line 2, in <module>
    from .kernel import CalystoHy
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/site-packages/calysto_hy/kernel.py", line 13, in <module>
    from hy.macros import _hy_macros, load_macros
ImportError: cannot import name '_hy_macros'

I searched in ~/apps/miniconda3/envs/hylang/lib/python3.6/site-packages/hy/macros.py, there isn't _hy_macros in this module.

Environment:

$ conda list|ag anaconda
anaconda                  custom           py36hbbc8b67_0  
anaconda-client           1.7.2                    py36_0  
anaconda-project          0.8.2                    py36_0  

$ conda list|ag python  
ipython                   7.2.0            py36h39e3cac_0  
ipython_genutils          0.2.0            py36hb52b0d5_0  
msgpack-python            0.5.6            py36h6bb024c_1  
python                    3.6.6             hd21baee_1003    conda-forge
python-dateutil           2.7.5                    py36_0  
python-libarchive-c       2.8                      py36_6  

$ conda list|ag hy    
# packages in environment at /home/leo/apps/miniconda3/envs/hylang:
calysto-hy                0.1.1                     <pip>
cryptography              2.3.1           py36hb7f436b_1000    conda-forge
hy                        0.15.0+64.ga42e17a           <pip>
jedhy                     1                         <pip>

Ubuntu 16.04.

dsblank commented 5 years ago

Hy must have changed. PRs accepted! :) Thanks for reporting.

HaiNguyen007 commented 5 years ago

I have same error, pls help

josiah14 commented 5 years ago

A potential solution, in the meantime, is to use Hy version 0.15.0. It's worth noting that this is the only way to get Hy running on Python 3.7 in Jupyter.

pip install git+https://github.com/hylang/hy.git@0.15.0 --force-reinstall
josiah14 commented 5 years ago

@HaiNguyen007 Have you had difficulty with defining Macros in my proposed workaround? I seem to not be able to...

In [22]: (defn parse-colon [sym]
       :     (list (map (fn [x]
       :                (if (empty? x)
       :                    None
       :                    (int x)))
       :              (.split (str sym) ":"))))
       :
Out[22]: [None]

In [23]: (defn parse-indexing [sym]
       :   (cond
       :     [(in ":" (str sym)) `(slice ~@(parse-colon sym))]
       :     [(in "..." (str sym)) 'Ellipsis]
       :     [True sym]))
       :
Out[23]: [None]

In [24]: (defmacro nget [ar &rest keys]
       :     `(get ~ar (, ~@(map parse-indexing keys))))
       :
Out[24]: [<function <lambda> at 0x7f203c8328c8>]

In [25]: (import [numpy :as np])
       :
Out[25]: [None]

In [26]: (setv a (np.array [[0 1 2 3 4 5] [10 11 12 13 14 15] [20 21 22 23 24 25] [30 31 32 33 34 35] [40 41 42 43 44 45] [50 51 52 53 54 55]]))
       :
Out[26]: [None]

In [27]: (nget a (, 1 2 3 4 5) (, 0 1 2 3 4))
       :
Traceback (most recent call last):
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/macros.py", line 194, in macroexpand
    obj = m(compiler.module_name, *tree[1:], **opts)
  File "<eval>", line 1, in <lambda>
NameError: name 'parse_indexing' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/calysto_hy/kernel.py", line 134, in do_execute_direct
    _ast = hy_compile(tokens, '', root=ast.Interactive)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 1723, in hy_compile
    result = compiler.compile(tree)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 350, in compile
    ret = self.compile_atom(tree)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 344, in compile_atom
    return Result() + _model_compilers[type(atom)](self, atom)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 1699, in compile_list
    elts, ret, _ = self._compile_collect(expression)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 423, in _compile_collect
    ret += self.compile(expr)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 350, in compile
    ret = self.compile_atom(tree)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 344, in compile_atom
    return Result() + _model_compilers[type(atom)](self, atom)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/compiler.py", line 1544, in compile_expression
    expression = macroexpand(expression, self)
  File "/home/josiah/miniconda3/envs/scipy-lectures/lib/python3.7/site-packages/hy/macros.py", line 201, in macroexpand
    raise HyMacroExpansionError(tree, msg)
hy.errors.HyMacroExpansionError:   File "None", line 1, column 1

HyMacroExpansionError: expanding `nget': NameError("name 'parse_indexing' is not defined")

It seems to work in the regular Hy REPL, though...

╰─$ hy
hy 0.15.0 using CPython(default) 3.7.2 on Linux
=> (import [numpy :as np])
=> (setv a (np.array [[0 1 2 3 4 5] [10 11 12 13 14 15] [20 21 22 23 24 25] [30 31 32 33 34 35] [40 41 42 43 44 45] [50 51 52 53 54 55]]))
=> (defn parse-colon [sym]
...     (list (map (fn [x]
...                (if (empty? x)
...                    None
...                    (int x)))
...              (.split (str sym) ":"))))
=>
=> (defn parse-indexing [sym]
...   (cond
...     [(in ":" (str sym)) `(slice ~@(parse-colon sym))]
...     [(in "..." (str sym)) 'Ellipsis]
...     [True sym]))
=> (defmacro nget [ar &rest keys]
...     `(get ~ar (, ~@(map parse-indexing keys))))
<function <lambda> at 0x7fdac66bf620>
=> (nget a (, 0 1 2 3 4) (, 1 2 3 4 5))
array([ 1, 12, 23, 34, 45])
Karrq commented 5 years ago

I've just tried installing it and it failed with the same error. Unfortunately I don't have nearly enough knowledge to fix this but it would be awesome if this kernel actually worked, since this is the only maintained kernel for Hy!

Karrq commented 5 years ago

@josiah14 @leetschau

I digged around and modified the code that loads the macros to reflect the newest changes. Unfortunately there are other problems that prevent any code from running which I'll try to investigate but looks like they are inherent on how the calysto_hy's kernel executes code. Anyways, if somebody wants to try out the now-installing kernel they can do so using my fork.

Karrq commented 5 years ago

I've modified the kernel yet again and now it runs! I tried your code, @josiah14 but the issue still persisted. I'll try modifying more and get to the bottom of this.

JeffCarpenter commented 5 years ago

@Karrq, your fork works for me! Time for a PR soon?

Karrq commented 5 years ago

It wasn't working for me last time I tried... Can you tell me what did you try?

JeffCarpenter commented 5 years ago

I believe all I've done here is pip install the repo, python3 -m calysto_hy install --user, and jupyter console --kernel=calysto_hy

Karrq commented 5 years ago

@JeffCarpenter I meant to ask if you tried to use the code posted by @josiah14, as you can't declare new macros but you can run the kernel normally.

hastebrot commented 5 years ago

To run the hy metakernel on Jupyter console and notebook I used following commands:

$ pip3 install --user --force-reinstall ipython jupyter jupyterlab
$ pip3 install --user --force-reinstall metakernel ipyparallel

$ pip3 install --user --force-reinstall git+https://github.com/hylang/hy.git@0.17.0
$ pip3 install --user --force-reinstall git+https://github.com/Karrq/calysto_hy.git

$ pip3 install --force-reinstall jupyter
$ python3 -m calysto_hy install --user

$ jupyter console --kernel calysto_hy
$ jupyter notebook --notebook-dir=.jupyter/

Versions:

josiah14 commented 4 years ago

@hastebrot I tried your exact instructions right now, and while the repl does boot up (in the case of Jupyter console) and you can type code in, and it highlights the syntax, it doesn't actually interpret any of the code entered by the end user. You can submit code, but no results are ever returned, and if you mess around long enough, you'll get this error message:

/home/josiah/miniconda3/envs/hyid3_and_seq/lib/python3.7/site-packages/jupyter_console/ptshell.py:661: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '
josiah14 commented 4 years ago

I also cannot import any Pip installed Python modules (like NumPy) in versions of Hy > 0.15 (so 0.15 is the latest version that I find actually usable).

Also still unable to run my macros inside of Jupyter Console on any version of Hy (obviously I guess, since not much has changed on version 0.15, and I can't get 0.16 and 0.17 working in any meaningfully useful way).

josiah14 commented 4 years ago

For others that come here, it appears that Hy and Calysto_Hy don't play nice with Conda/Anaconda created virtualenvs. I got everything except macros in the jupyter console working using pipenv on Hy 0.17.0 and Calysto_Hy 0.1.1.

gptix commented 4 years ago

Sad face. I like Lisp a lot, and have to write Python now, and want to show off Hy at the Atlanta Functional Programming Meetup, to show macros. And everybody loves Jupyter...

idmyn commented 4 years ago

for what it's worth, I got the console working following @hastebrot's comment, but I did also need pip3 install --force-reinstall --user notebook before python3 -m calysto_hy install --user ran successfully

atgmello commented 4 years ago

Sorry for spamming this issue, but I believe I got it working now! I'll gladly change anything in my PR if it's not ideal. Hopefully there will be no more sad faces for not having macros in Jupyter. :)

josiah14 commented 3 years ago

I'm glad things seem to be working for most people. However, it's noteworthy that Macros now aren't working in either Jupyter Lab/Notebook or Jupyter Console. I've moved-up to using Hy 0.19.0, and I'm pleased at least to see that the basics are working, though.

jupyter-lab-calysto_hy

I figured this comment wouldn't be considered spamming the ticket since it's still open and there also hasn't been a ton of activity on it.

josiah14 commented 3 years ago

Hy is pretty neat, but the lack of Jupyter stability causes me to recommend it to my more advanced engineers/engineering teams, but not so much to data scientists looking for a more convenient Python for data exploration. It would be really cool if Hy could serve that purpose in the future, though, as LISP was designed around "list processing", and most data science work is working with multidimensional list-like structures.

atgmello commented 3 years ago

Huh that's weird. That's exactly what I solved with my PR, which has already been merged for quite some time now (so maybe this issue should be closed after we investigate @josiah14's case, @dsblank?).

I've installed everything from scratch with this simple requirements.txt

jupyterlab
numpy
hy==0.19.0
git+https://github.com/Calysto/calysto_hy.git
git+https://github.com/ekaschalk/jedhy.git

on a clean Python 3.8.0 virtualenv and your exact example is running fine.

image

Can you confirm that you have the latest Calysto Hy?

atgmello commented 3 years ago

Hy is pretty neat, but the lack of Jupyter stability causes me to recommend it to my more advanced engineers/engineering teams, but not so much to data scientists looking for a more convenient Python for data exploration. It would be really cool if Hy could serve that purpose in the future, though, as LISP was designed around "list processing", and most data science work is working with multidimensional list-like structures.

Also, this. That's precisely why I wanted to give this issue a shot. I'm quite busy atm, but I should soon start posting about and spreading some Hy and Calysto Hy awareness on my personal blog, targeting my DS friends. Glad to see more people interested in bringing Hy to Data Science!

dsblank commented 3 years ago

@atgmello Yes, please advise what to do. We definitely would like to make Calysto Hy as good as we can make it.

@josiah14 How did you install Calyso Hy? Maybe we just need to push a release out to pypi?

atgmello commented 3 years ago

Oh I believe that Calysto Hy is doing great already! I think that it is working just as expected now.

One thing that still bugs me though is the lack of image inlining. I wish I had more time to tackle https://github.com/Calysto/calysto_hy/issues/6, since I actually prefer working in Emacs rather than using the browser, most of the times. So I needed inlining in order to properly display images in Emacs. I tried looking into it but the code rabbit whole is just too deep for me right now.

For now I resort to either accepting my fate and turning to Jupyter Lab in my browser or sticking to Emacs and simply saving the image to disk and displaying it in another buffer.

Maybe we just need to push a release out to pypi?

Yeah, if the latest changes haven't been pushed to PyPI yet then that might be it.

Actually, I haven't even tried installing Calysto Hy from PyPI before because the README does not point to that option in the installation process. Maybe the README should be updated as well?

josiah14 commented 3 years ago

I won't get time again to toy with this until Wednesday, so I'll check back in with you guys then and see what I can get working.

actsasgeek commented 2 years ago

FWIW, I'm having this issue with Hy 0.24 today.

epgui commented 2 years ago

I also have the same issue with all the latest versions, using python 3.9.9:

# requirements.txt

# ...
calysto-hy==0.1.1
hy==0.24.0
jedhy==1.0.0
jupyterlab==3.4.4
# ...
# docker-compose.yml
  # ...
  jupyter-server:
    build: .
    command: >
      /bin/bash -c '
        python3 -m calysto_hy install &&
        alembic upgrade head &&
        jupyter lab --ip 0.0.0.0 --no-browser --allow-root
      '
  # ...

Error:

jupyter-server  | Traceback (most recent call last):
jupyter-server  |   File "/usr/local/lib/python3.9/runpy.py", line 188, in _run_module_as_main
jupyter-server  |     mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
jupyter-server  |   File "/usr/local/lib/python3.9/runpy.py", line 147, in _get_module_details
jupyter-server  |     return _get_module_details(pkg_main_name, error)
jupyter-server  |   File "/usr/local/lib/python3.9/runpy.py", line 111, in _get_module_details
jupyter-server  |     __import__(pkg_name)
jupyter-server  |   File "/usr/local/lib/python3.9/site-packages/calysto_hy/__init__.py", line 2, in <module>
jupyter-server  |     from .kernel import CalystoHy
jupyter-server  |   File "/usr/local/lib/python3.9/site-packages/calysto_hy/kernel.py", line 13, in <module>
jupyter-server  |     from hy.macros import _hy_macros, load_macros
jupyter-server  | ImportError: cannot import name '_hy_macros' from 'hy.macros' (/usr/local/lib/python3.9/site-packages/hy/macros.py)
jupyter-server exited with code 1
actsasgeek commented 1 year ago

@epgui This isn't even the last error. I tried commenting out that part of the import but modules have been renamed and code has changed. It seems that Hy had a major re-write of the internals. I tried mucking with it for an hour or so but I just don't know enough about what the various parts do and how MetaKernel works. I would love to use Hy but a lack of Jupyter support is a deal breaker.