quarto-dev / quarto-vscode

Quarto extension for VS Code
https://marketplace.visualstudio.com/items?itemName=quarto.quarto
MIT License
112 stars 11 forks source link

Autocomplete Python #10

Closed AlissonRP closed 1 year ago

AlissonRP commented 2 years ago

My R codes have autocomplete but If I write Python code in .qmd format for some reason my codes don't have autocomplete. When I use .ipynb and .py it's okay, is there some configuration that is disabled or maybe can cause conflict?

Example

my configs: Quarto extension version: 1.12.1 VSCode version: 1.66.2 OS: Ubuntu 20.04.4 LTS python extension: v2022.4.1

jjallaire commented 2 years ago

Not sure why this would be! (not seeing any problem here and running the same version). You could check the "Debug Console" tab to see if there are any errors occuring?

AlissonRP commented 2 years ago

No errors in the Debug Console, I tested some things here, and sometimes the autocomplete "almost" works (idk why sometimes tbh) but not correctly, like this:

but..

danieltomasz commented 2 years ago

For me the Python autocompletion works too

henningsway commented 2 years ago

For me the autocompletion in *.qmd also works for R but not for Python. I get the same "meaningless" autocomplete suggestions as @AlissonRP and there are also ne errors in the Debug Console. Autocompletion works for Python and Jupyter Files.

Ubuntu 20.04.4 LTS VSCode 1.68.1 Quarto Extension: 1.25.0 Python Extension: 2022.10.0

(Deactivation Github Copilot Extension did not solve the problem)

henningsway commented 2 years ago

Apparently sth may be wrong with my jupyter kernel - not sure if this is related.

The kernel points to an environment in another project, which doesn't exist anymore. I'm not quite sure, where this is specified, as I just created this project from scratch.

(pyenv) hb@funbook:~/hrv/quarto-test$ quarto check jupyter

[✓] Checking Python 3 installation....OK
      Version: 3.8.8
      Path: /home/hb/hrv/quarto-test/pyenv/bin/python3
      Jupyter: 4.11.1
      Kernels: coconut_py2, python388jvsc74a57bd00d442098b151dd64b6e85aae2d5689d38b05d1f12f914dfc5f3d6054c9563b68, coconut, coconut_py, coconut_py3, python388jvsc74a57bd062f11df79ebc848ceb58f59a491174b612dd85619d9e0c9304e8c10989b33e78

(|) Checking Jupyter engine render....2022-07-08 23:11:48,846 - traitlets - ERROR - Failed to run command:
['/home/hb/repos/myhrv/data-analysis/.venv/bin/python', '-m', 'ipykernel_launcher', '-f', '/tmp/tmp8trkw7rc.json']
    PATH='/home/hb/repos/myhrv/data-analysis/.venv/bin:/home/hb/.poetry/bin:/home/hb/.pyenv/shims:/home/hb/.pyenv/bin:/home/hb/.local/bin:/home/hb/bin:/home/hb/.local/bin:/home/hb/.pyenv/plugins/pyenv-virtualenv/shims:/home/hb/.pyenv/shims:/home/hb/.pyenv/bin:/home/hb/.poetry/bin:/home/hb/.pyenv/shims:/home/hb/.pyenv/bin:/home/hb/.local/bin:/home/hb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
    with kwargs:
{'stdin': -1, 'stdout': None, 'stderr': None, 'cwd': None, 'start_new_session': True}

2022-07-08 23:11:48,847 - traitlets - ERROR - [Errno 2] No such file or directory: '/home/hb/repos/myhrv/data-analysis/.venv/bin/python'
Traceback (most recent call last):
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/manager.py", line 75, in wrapper
    out = await method(self, *args, **kwargs)
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/manager.py", line 389, in _async_start_kernel
    await ensure_async(self._launch_kernel(kernel_cmd, **kw))
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/utils.py", line 38, in ensure_async
    return await obj
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/manager.py", line 307, in _async_launch_kernel
    connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/provisioning/local_provisioner.py", line 204, in launch_kernel
    self.process = launch_kernel(cmd, **scrubbed_kwargs)
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/launcher.py", line 170, in launch_kernel
    raise ex
  File "/home/hb/hrv/quarto-test/pyenv/lib/python3.8/site-packages/jupyter_client/launcher.py", line 158, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/home/hb/.pyenv/versions/3.8.8/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/hb/.pyenv/versions/3.8.8/lib/python3.8/subprocess.py", line 1706, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/hb/repos/myhrv/data-analysis/.venv/bin/python'

[Errno 2] No such file or directory: '/home/hb/repos/myhrv/data-analysis/.venv/bin/python'
[✓] Checking Jupyter engine render....OK
jjallaire commented 2 years ago

That kernel is for whatever reason still registered on your system. Try using the jupyter kernelspec command to remove the old kernel.

Fred-Wu commented 2 years ago

This happens to me too. But my kernel check returns without any issues.

(myenv) C:\MHLL>quarto check jupyter

[>] Checking Python 3 installation....OK
      Version: 3.9.13 (Conda)
      Path: C:/Users/xxxxxx/AppData/Local/miniforge3/envs/myenv/python.exe
      Jupyter: 4.11.0
      Kernels: python3

[>] Checking Jupyter engine render....OK
henningsway commented 2 years ago

I just tested this on a brand new M1 Macbook and autocomplete also doesn't work here, but the notebook executes and renders nicely.

MacOS 12.5 VSCode: 1.69.2 Extensions: Python (+Jupyter, Pylance, etc), Nord Theme, Quarto (v.1.29.0)

Python interpreter from an virtual environment.

mdefende commented 2 years ago

I also can't get the code autocomplete to work for anything in qmd code chunks. However instead of popping up a tab with something to select at all, it just inserts a tab character. The code complete works in .ipynb files though. Just wondering if there were other steps I needed to take other than installing quarto and the VSCode extension.

OS: Windows 10.0.19044 VSCode: 1.70.0 Quarto: 1.0.38 Python Extension: v2022.12.0

Ben-Choat commented 2 years ago

I am having the same behavior as mdefende. Zero signs of autocomplete working when working in a .qmd file. .ipynb works just as expected though.

May need to open another issue, but rendering from a .qmd file also fails but works as expected from .ipynb. Code executes as expected in .qmd and .ipynb files.

Nevermind on the second issue. Was able to navigate to the directory where the .qmd file was located using the terminal, activate the appropriate conda env, and the 'quarto render file.qmd --to html' worked as expected. I still cannot render from within vs code however. I also note, that my default settings in the user settings.json file has a files.associations: {"(.rmd": "markdown"}, but nothing for .qmd. Not sure if this is helpful or not. I cannot find anything about creating file associations for .qmd files.

LiamBurke24 commented 2 years ago

I am having a similar issue with python autocomplete in .qmd documents. Works fine in .ipynd docs as noted above.

OS: 12.0.1 VSCode: 1.71.0 Quarto: 1.38.0 Python Extension: v2022.14.0

@Ben-Choat what system are you using?

stephenleo commented 2 years ago

same issue. I do not see python autocomplete in *.qmd files Render works fine though

oszaar commented 2 years ago

Same issue. Not sure if is the system or due to conflicts with other extension

OS: 12.5.1 VSCODE: 1.71.2 (Universal) Quarto: 1.1.245 Quarto- VSCODE extension : v1.38.0 Python Extension: v2022.14.0

Bonnevie commented 1 year ago

I understand resources are limited, but is there a roadmap for fixing this issue? It really limits adoption of Quarto by python users outside of using ipynb.

jjallaire commented 1 year ago

Hi there, just to be clear the issue you are seeing is not widespread (the feature does work on all systems I've seen). If I could reproduce the problem I'd fix it immediately but sadly I can't! From what I've seen the source of trouble normally comes down to something like a stray/old environment variable pointing to a different version of Python. Hard for me to find a general solution for this sort of problem!

You could check the Output => Extension Host and Debug Console for error messages that may have been logged in attempting to bootstrap completion. Perhaps they provide some clue?

Fred-Wu commented 1 year ago

Actually I does not work at all on my macbook,

It only works for the library, but with bugs too.

Nothing gets suggested after typing np.

import numpy as np
np.

Also for library itself, if it shows numpy, then you select it, then it duplicates the selection like import numpnumpy

Bonnevie commented 1 year ago

@jjallaire I think the issue raised in the OP might not apply anymore, but other issues related to Python autocomplete in this project get noted as duplicates and redirected here, so the newer issues might be more reflective of the experienced problem. My issue is closer to that reported by @Fred-Wu. I just tried pruning the majority of my extensions sans Python/Pylance and Jupyter and a few others to get a fairly clean environment, and still my autocomplete looks like this: image Note that the suggestions are part of pandas, so so-far-so-good, but it doesn't react at all to what comes after pd.. And as Fred noted, actually going down the list and completing with pd.Series leads to: image

quarto check jupyter does not raise any errors.

jjallaire commented 1 year ago

Okay, I see that now. Something has changed in either VS Code or the Python extension that has made this stop working. Hopefully there is a way to recover the previous behavior! Will investigate and report back.

jjallaire commented 1 year ago

I believe that I've gotten to the bottom of this issue. The fix is here: https://github.com/quarto-dev/quarto-vscode/commit/1755d70ca197bdd68413be9b6a81c8133bbd21b3.

This fix is in the v1.56.0 release which is available now.