-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support poetry virtual environments #8372
Comments
We actually don't support poetry environments automatically (see environment docs on where we do look). When we added support for installing dev dependencies via poetry the environment support wasn't working. I have turned this issue into a feature request to see if people 👍 the original comment to help us decide work priorities. I will also say that you can work around this by setting |
This issue is about even I did |
Oh, I find that only add the setting in |
For me, adding |
What fixed it for me was to manually specifiy in the .vscode/settings: "python.pythonPath": "~/.cache/pypoetry/virtualenvs/app-sNwkCRg1-py3.6" |
It was the python Venv Path for me |
Correct, you can set |
Setting |
Poetry 1.0.0 (stable) has been released! |
Simple python script if you want to set it and forget it (requires #!/usr/bin/env python3
import json
import subprocess
from pathlib import Path
venv_path = subprocess.check_output("poetry env info --path".split())
venv_path = venv_path.decode("UTF-8")
settings = dict()
Path(".vscode").mkdir(parents=True, exist_ok=True)
Path(".vscode/settings.json").touch()
with open(".vscode/settings.json", "r") as f:
settings = json.load(f)
settings["python.pythonPath"] = venv_path
with open(".vscode/settings.json", "w") as f:
json.dump(settings, f, sort_keys=True, indent=4)
print(json.dumps(settings, sort_keys=True, indent=4)) |
I don't know if it's a version thing (I'm on Poetry 1.0.0 and macOS 10.14) but Poetry virtualenvs are stored at |
Hi everyone, we now support Poetry in the Insiders build of the extension. You can use the command You can also download and install latest insiders build from here https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix. |
@karrtikr - This is awesome - thank you! On loading the Python Extention's Insiders build, I immediately found the option to use the poetry's python interpreter. 🎉 From what I can tell, tests and libraries are all working correctly now with Poetry. Do we need to modify any other paths in settings.json (linters, pytest, venv paths, etc.), or is this the only step? |
was my result. ubuntu 21.10, python 3.9.4-1 from dist. |
@aaronsteers Awesome. Nope, you do not need to configure anything. We'll roll this out in the stable marketplace build soon. @donbowman You'll need to install Jupyter extension from the VSCode marketplace. Click the marketplace icon and search for |
that extension is only available on the 'insiders' build of vscode as well. so its not just putting the python one to 'insiders', its changing the whole thing. Is there a reason they need to be tied together? I don't use jupyter. I'll try to find a time to change the environment over to try. |
@donbowman they are tied together because the Jupyter extension was spun out of this extension in November and we haven't fully decoupled them yet. We are actively working towards breaking the dependency, but we are obviously not there yet. |
@karrtikr - So far, this has been a fantastic experience. I have one piece of feedback I wanted to share here. (Lmk if I should log elsewhere.) I can see that now all of my terminal windows are starting automatically in the poetry virtual environment, which is awesome. However, when I try using Two things I thought might be helpful: (1) After sending the Thanks again! |
@donbowman - FWIW, I'm not on the Insider build of VS Code but I was still able to install the insider version of this plugin. I already had Jupyter plugin installed though, probably from a while back. I'm on VS Code |
@aaronsteers thanks for the feedback!
Not sure as pipx is supposed to install entirely new virtual environments, so I would think either pipx expects to not be in a virtual environment or it's a bug for them.
There's two issues with that. One, this would inevitably break people's code (we already have issues with race conditions doing the activation, so tossing in an echo or something to print the instructions isn't going to help 😉). Two, I don't know if we want to get into the teaching area for this sort of thing. Not wanting an activated environment versus not is already somewhat of an advanced topic (heck, environments period seem to be a generally unknown thing for folks). So I suspect we would prefer to err on the side of simple (plus people typically want the activation more than not wanting it).
Once again, this is bit advanced for a lot of folks. Regardless of my feedback, if you would like us to consider these feature requests then please open discussions at https://github.com/microsoft/vscode-python/discussions/categories/ideas, otherwise we are bound to lose track of them. |
@brettcannon - Thanks for hearing my feedback and for your thoughtful response. Those points you raised make a lot of sense, I think. I think you've made a good case for not changing the core functionality. If there's some type of documentation that the Python extension also is auto-activating the poetry environment in all shells (in addition to the native python-based stuff like tests), that could be helpful. This could be a new section in the docs, or just a quick blurb here or here. I do think overriding the shell behavior is awesome - and also probably a big enough change to default VS Code behavior that it would be good to have clearly documented. Thanks! |
@aaronsteers automatic activation is documented at https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment. If you think there's something to clarify there then that can be opened at https://github.com/microsoft/vscode-docs. |
This is what worked for me. after creating the virtual environment with poetry it was not been detected by vscode in python interpreter selection (shift+cmd+p) even after restart.
However the problem is virtual environment doesn't get activated automatically as it does for pipenv as vscode everytime vscode is closed and restarted again. |
That's because your solution is bypassing the Poetry support in VSCode (which handles activating the active Poetry env), and is just using the "search a directory for virtual envs" support that already existed in the plugin. See #8372 (comment) |
To the maintainers - do you have a general eta for when you expect this to GA? Not intending to rush it but curious if this is expected in the coming month or further out. Thanks! |
@aaronsteers current plan is next week with our 2021.5 release. |
Poetry support is now available on version 2021.5! |
This doesn't appear in the changelog for version 2021.5 ! |
My virtual env creation doesn't get triggered automatically as soon I cd into the directory containing toml file. Whereas this happens for pipenv. |
@farhan3sixty1 Can you please create a new issue filling the issue template. I'm unclear on the problem you're referring to. @cailloumajor Yes, actually it was already available for 20% of users before (when we added it in the changelog), we just rolled it out to everybody. |
Environment data
Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:33:40.634Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 5.3.0-19-generic
poetry version: 1.0.0b2
Expected behaviour
Show poetry virtualenvs in
~/.cache/pypoetry/virtualenvs
Actual behaviour
Virtualenvs in above not been shown.
Steps to reproduce:
pip install poetry
.poetry init
.. ~/.cache/pypoetry/virtualenvs/<youprojectname>-b7g26Unn-py3.7/bin/activate
~/.cache/pypoetry/virtualenvs
,~/.cache/pypoetry/
,~/.cache/
to settings -> Python: Venv Folders and Python: Venv Path.Logs
Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)Where the virtualenvs folder:
ls ~/.cache/pypoetry/virtualenvs -l
The text was updated successfully, but these errors were encountered: