Skip to content

Default Python environment isn't the latest version #22364

Closed

Description

@pfmoore

Type: Bug

Open a new VS Code instance on a new file, and set the file type to Python. The default Python environment is "3.11.6 64-bit (Microsoft Store)". However, I have Python 3.12 installed from python.org, which is a later version and so should be the default to use.

The Python versions I have installed are: 3.12.0, 3.11.6, 3.10.11, 3.9.13, 3.8.10, all from python.org. All installed as default, not added to PATH. I access them using the py launcher. Plus, 3.11.6 from the Microsoft Store, configured to not provide python.exe on PATH.

So by default I do not have python available as a command from PATH, but I do have py, which by default runs Python 3.12.

Note that I do not want to set an explicit Python path in my configuration, as that would need changing whenever a new version of Python is released. I am aware of python.pythonPath and it does not address my issue.

Extension version: 2023.18.0
VS Code version: Code 1.83.1 (f1b07bd25dfad64b0167beb15359ae573aecd2cc, 2023-10-10T23:48:05.904Z)
OS version: Windows_NT x64 10.0.22621
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.73GB (15.34GB free)
Process Argv --crash-reporter-id d99325fe-b12a-45c2-b763-29c3a74b710e
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263cf:30856253
vscaat:30438848
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
89544117:30613380
a9j8j154:30646983
showlangstatbar:30737416
0bi6i642:30841073
a2ce3375:30757347
57b77579:30736110
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
copilotsettingt:30859503
synctok:30869157
dsvsc013:30795093
dsvsc014:30804076
pythonmhint1:30842940
dsvsc015:30845448
pythontestfixt:30871694
pythonregdiag2:30871582
pyreplss1:30865275
pythoncet0:30866520
pythontbext0:30864172

Activity

  1. karrtikr commented on Oct 27, 2023

    @karrtikr

    Ideally, we do select the highest version as the default, but that's supposed to change with #19818.

    Try the Python: Clear cache and reload window command and see the latest version gets selected. You can also select which ever Python version you want using Python: Select Interpreter command.

  2. pfmoore commented on Oct 27, 2023

    @pfmoore
    Author

    Try the Python: Clear cache and reload window command and see the latest version gets selected.

    No, that made no difference.

    You can also select which ever Python version you want using Python: Select Interpreter command.

    As I said, that would either require me to manually select for every new project, or it would mean hard coding a path which would then need manually updating when a new Python version comes out.

    Ideally, we do select the highest version as the default, but that's supposed to change with #19818.

    So how would I (either now or after #19818 is implemented) configure things so that I always default to the latest version of Python that's available on my PC? That's what the py launcher does by default and it's what I want VS Code to do as well. It seems to me that if #19818 is going to make the python command use the selected interpreter in terminal windows, ignoring how my PATH is set, it becomes even more important that the default is consistent with the launcher.

  3. karrtikr commented on Oct 27, 2023

    @karrtikr

    Try adding the following to User settings:

    "python.defaultInterpreterPath": "py"

    after clearing cache using the earlier command.

  4. karrtikr commented on Oct 27, 2023

    @karrtikr

    I've changed #19818 to first look into the "python" available on PATH, in your case it does not exist. So it will then try looking for "py" in PATH, thereby solving your issue automatically.

  5. pfmoore commented on Oct 28, 2023

    @pfmoore
    Author

    Thanks, but to be clear, I knew that I could change defaultInterpreterPath. I raised this as a bug, not as a question about how to make VS Code do what I want, because (a) I already know how to change the settings, and (b) I believe that the current behaviour is wrong. In fact, in #19818 you say "Currently in case of global interpreters, the interpreter with the highest version is preferred", which demonstrates that you also expected that behaviour. So could you at least explain to me why my environment is triggering this bug? Even if you don't intend to fix it, I'd like to know how I can avoid triggering it in the first place.

    Changing defaultInterpreterPath is something I'd potentially have to do on every PC I used VS Code on, and it would still give the wrong result if I later installed a store Python with a newer version. So it's at best a workaround for what I want (and what the current code is supposed to do) which is select the latest version of Python that VS Code has discovered on my PC.

    I've changed #19818 to first look into the "python" available on PATH, in your case it does not exist. So it will then try looking for "py" in PATH, thereby solving your issue automatically.

    But it won't, because if I uninstall the python.org 3.12 and 3.11 interpreters on my PC, I'd expect the Store 3.11 to be used by default. And the above rule won't do that - it will use 3.10, which the py command will choose.

    I'm not completely against the idea that the rule is "select the interpreter that would be run when the user types python at a command prompt, or if there is no such interpreter, then the one that would be run when the user types py". But it's a change in behaviour, and as such, I think it should be documented properly, and users warned of the incompatibility. But that's a separate issue, as the situation now is supposed to be "newest version is the default".

  6. karrtikr commented on Oct 29, 2023

    @karrtikr

    "Currently in case of global interpreters, the interpreter with the highest version is preferred", which demonstrates that you also expected that behaviour.

    Correct.

    So could you at least explain to me why my environment is triggering this bug? Even if you don't intend to fix it, I'd like to know how I can avoid triggering it in the first place.

    Well if we investigate on the why, we may as well fix it 🙂 The reason I am hesitant to spend time on this is because this priority order is going to change anyways.

    And the above rule won't do that - it will use 3.10, which the py command will choose

    Yep, the behavior that you desire (select the highest version) is not expected behavior we've planned for with #19818, as we believe "select the interpreter that would be run when the user types python or py" is more intuitive based on our experience, especially for beginners.

  7. karrtikr commented on Oct 29, 2023

    @karrtikr

    If you still wish, we can definitely investigate further, in that case please provide the debug logs which can help diagnose the issue:

    • Run Developer: Set log level command
    • Select Trace
    • Run Developer: Reload Window command
    • Provide the output:
    Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

    XXX
    

    Note we investigate issues in order based on priority and severity, which includes the impact it has on your ability to use the extension to do productive work, and the number of people affected. If other users come forward and leave a comment demonstrating they are seeing/reproducing the problem then we will raise this issue's priority. Thanks for understanding and the patience!

  8. pfmoore commented on Oct 30, 2023

    @pfmoore
    Author

    Thanks. I would like to know what's going on here, not least because if my setup is somehow triggering this (currently incorrect) behaviour, I'd like to understand what's unusual about it. As far as I can see, I haven't done anything particularly odd...

    Here's the requested output: https://gist.github.com/pfmoore/0ca95c2b6158e7251a9240f5272c639f (it was too big to include inline).

  9. 13 remaining items

  10. karrtikr commented on Oct 30, 2023

    @karrtikr

    Try installing the following VSIX: https://github.com/microsoft/vscode-python/suites/17758603869/artifacts/1017230519 using Extension: Install from VSIX command and see if it helps.

  11. karrtikr commented on Oct 30, 2023

    @karrtikr

    I'm thinking to not consider "py" when auto-selecting #19818, as it does not seem to solve the issue for the target audience. If users want that they can always configure it: #22364 (comment).

    This way you can also have this behavior intact even after #19818.

  12. pfmoore commented on Oct 30, 2023

    @pfmoore
    Author

    Try installing the following VSIX

    Sure. Can you just confirm before I do (1) what it is, and (2) how I revert to my current setup after I've done whatever you want me to with this?

    I'm thinking to not consider "py" when auto-selecting #19818, as it does not seem to solve the issue for the target audience.

    I'm not sure who you consider to be the "target audience" for discovering Python installations. Am I not a member of the target audience? If so, why is that? I don't consider my setup to be incredibly unusual. Yes, having multiple Python installs isn't common, but for any developer wanting to test on multiple versions it's perfectlyt normal.

    If you don't support the py launcher, then you're not really following the standard PEP for accessing Python on Windows, and in particular you are disadvantaging users of the python.org distributions of Python, as they won't have python on their path, and they will rely on the launcher.

  13. karrtikr commented on Oct 30, 2023

    @karrtikr

    Sure. Can you just confirm before I do (1) what it is, and (2) how I revert to my current setup after I've done whatever you want me to with this?

    It's a packed version of the Python extension that contains a potential fix. You can uninstall it or go back to installing the current version using this UI:

    image

  14. pfmoore commented on Oct 30, 2023

    @pfmoore
    Author

    Nice - that seems to have worked - I installed the build and then did "Clear cache and reload window" and I now get 3.12. Can you explain what it was that was in my setup causing the incorrect result in the original version?

  15. karrtikr commented on Oct 30, 2023

    @karrtikr

    Cool - it was nothing due to your setup, we just seemed to inadvertently prefer Microsoft store interpreters over other global interpreters in that compare() function I linked earlier: #22380.

    By my earlier comment, I was referring to the target audience of #19818, which is mainly the beginners who would benefit by us changing default global interpreter to "python".

  16. removed
    needs spikeLabel for issues that need investigation before they can be worked on.
    on Oct 30, 2023
  17. pfmoore commented on Oct 30, 2023

    @pfmoore
    Author

    Nice! Thanks so much for continuing to look at this - I appreciate your help. I'm still not 100% sure I understand the implications of #19818 yet, but I'll think about that some more and follow that issue for more details.

  18. locked as resolved and limited conversation to collaborators on Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions