microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

imports not working can't change python intepreter #23173

Open edenpage11 opened 7 months ago

edenpage11 commented 7 months ago

Type: Bug

When i pip installed exifread and reverse_geocoder, they say not resolved. I have my intepreter set as python3.12.2 in the bottom right corner and all the settings, but typing python --version in my terminal shows it as 3.9.13. I have uninstalled and reinstalled, closed and reopened, idk what else to do, I also can run the program if I change it to 3.9.13 in the bottom right corner and the not resolved errors go away

VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:20:17.278Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 x 2995)| |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
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|15.85GB (5.77GB free)| |Process Argv|--crash-reporter-id b84be46c-f11e-428a-ac42-896d8d8b8bc8| |Screen Reader|no| |VM|33%|
Extensions (19) Extension|Author (truncated)|Version ---|---|--- nodejs-bundle|1Yi|1.0.0 svelte-bundle|1Yi|1.0.0 svelte-intellisense|ard|0.7.1 vscode-svelte-snippets|fiv|0.5.0 svg|joc|1.5.3 rainbow-csv|mec|3.11.0 debugpy|ms-|2024.2.0 isort|ms-|2023.10.1 python|ms-|2024.2.1 vscode-pylance|ms-|2024.4.1 jupyter|ms-|2024.2.0 vscode-jupyter-cell-tags|ms-|0.1.8 vscode-jupyter-slideshow|ms-|0.1.5 live-server|ms-|0.4.13 powershell|ms-|2024.0.0 vs-code-prettier-eslint|rve|6.0.0 vscode-standard|sta|2.1.3 svelte-vscode|sve|108.3.4 vscode-surround|yat|1.5.0
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 vscaac:30438847 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 ccp2r3:30993541 dsvsc020:30976470 pythonait:31006305 7ghi1836:30988842 dsvsc021:30996838 g1icg217:30999571 ```
edenpage11 commented 7 months ago

image

deleting and reopening the terminal also didn't fix it

karthiknadig commented 7 months ago

@edenpage11 we use whatever python you have on PATH in your terminal environment when you are using global python. You can use where python to see which python is being used.

Here are some of our recommendations based on best practices.

  1. Use virtual environment: In your case you are installing packages using pip binary directly. Just like how python can point to different python depending on how the PTH environment variable is set, pip can point to different locations. Installing packages into global environment can actually break your global python install. So, we recommend always creating virtual environment for each of the projects. You can do this using Python: Create Environment command from command palette and selecting Venv. When you use virtual environments, Python extension can make sure that python means the python in your virtual environment.
  2. Always use python -m pip install instead of pip install. Read this for more details on why: https://snarky.ca/why-you-should-use-python-m-pip/

Here is an example in my case, it really depends on what PATH env variable is doing for global environments: image

Here is a virtual environment. With virtual environments, Python extension can "activate" it and add it to PATH in such a way that python is going to be the one in the virtual environment. image

edenpage11 commented 7 months ago

Is there a way to make it default to the 3.12? I don't want it to run the 3.9 at all

Using the where python also didn't print any paths

karthiknadig commented 7 months ago

@edenpage11 You can do it two ways.

Option 1

set PATH environment variable using this UI in windows: image

image

image

image

You will need to add the folder containing the python you want at the top: image

NOTE: You need to add the path folder containing the python, not the path to python binary itself.

Option 2

Uninstall the python 3.9. You can find where it is installed by using python -c "import sys;print(sys.executable)"