microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 768 forks source link

VS Code + Pylance does not find venv-installed modules while venv is activated #3881

Closed omeinusch closed 4 months ago

omeinusch commented 1 year ago

Type: Bug

I use VS Code Version: 1.74.3 on MacOS 13.2. python -V returns Python 3.11.1.

I get the following error message: Import "django.shortcuts" could not be resolved from source Pylance(reportMissingModuleScource).

enter image description here

As you can see in the screenshot, the correct venv is activated and includes Django.

enter image description here

I also tried or checked:

  1. https://stackoverflow.com/q/68486207/2321643
  2. https://stackoverflow.com/a/65802367/2321643 but
  3. the suggested solution with reloading the windows did not help.
  4. reinstallation the virtual environment within VSCode and installing Django again
  5. re-selecting the venv.
  6. deleting all python-specific settings in user/settings.json as well as .vcode/settings.json.
  7. Reinstallation python and associated extensions.

Using Debug I can safely run my Django-application without any import issues. What do I need to do that Pylance does not issues these problems?

Extension version: 2023.1.40 VS Code version: Code 1.74.3 (97dec172d3256f8ca4bfb2143f3f76b503ca0534, 2023-01-09T17:07:18.579Z) OS version: Darwin x64 22.3.0 Modes: Sandboxed: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz (8 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|2, 2, 2| |Memory (System)|8.00GB (0.02GB free)| |Process Argv|--crash-reporter-id c34e57bf-a857-44cb-9ef9-829c9efee533| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes516:30244333 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vsdfh931cf:30280410 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593cf:30376535 pythonvs932:30410667 cppdebug:30492333 vsclangdf:30486550 c4g48928:30535728 dsvsc012cf:30540253 azure-dev_surveyone:30548225 pyindex848cf:30577861 nodejswelcome1cf:30587006 3biah626:30602489 pyind779:30647091 f6dab269:30613381 a9j8j154:30646983 ```
heejaechang commented 1 year ago

I just tried it and it works as expected.

Can you provide us some logs as described in the troubleshooting guide?

and also provide us list of packages in the .venv/lib/python3.11/site-packages

without that information, there is not much we can do.

omeinusch commented 1 year ago

Thank you for the fast response. First find the list of installed packages.

% ls  .venv/lib/python3.11/site-packages 
Django-4.1.5.dist-info      distutils-precedence.pth    pkg_resources           sqlparse-0.4.3.dist-info
_distutils_hack         django              setuptools
asgiref             pip             setuptools-65.5.0.dist-info
asgiref-3.6.0.dist-info     pip-22.3.1.dist-info        sqlparse

And this is the log Python Language Server:


[Info  - 6:29:25 PM] (19530) Pylance language server 2023.1.40 (pyright e96b3ece) starting
[Info  - 6:29:25 PM] (19530) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist
[Info  - 6:29:25 PM] (19530) Starting service instance "mysuperproject"
[Info  - 6:29:25 PM] (19530) Auto-indent enabled
[Info  - 6:29:26 PM] (19530) No configuration file found.
[Info  - 6:29:26 PM] (19530) No pyproject.toml file found.
[Info  - 6:29:26 PM] (19530) Setting pythonPath for service "mysuperproject": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 6:29:26 PM] (19530) stubPath /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/typings is not a valid directory.
[Info  - 6:29:26 PM] (19530) Assuming Python platform Darwin
[Info  - 6:29:26 PM] (19530) Search paths for /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib
[Info  - 6:29:26 PM] (19530)   /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject
[Info  - 6:29:26 PM] (19530)   /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/typings
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stubs/...
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs
[Info  - 6:29:26 PM] (19530) Adding fs watcher for directories:
 /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject
[Info  - 6:29:26 PM] (19530) Searching for source files
[Info  - 6:29:26 PM] (19530) Found 20 source files
(19530) [IDX(FG)] index libraries /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject (index) ...
(19530) [IDX(FG)]   read stdlib indices (49ms)
(19530) [IDX(FG)] index libraries /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject (index) [succeed] (55ms)
(19530) [FG] parsing: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (25ms)
[Info  - 6:29:26 PM] (19530) Could not resolve source for 'django.shortcuts' in file '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py'
[Info  - 6:29:26 PM] (19530)   Looking in root directory of execution environment '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject'
[Info  - 6:29:26 PM] (19530)   Attempting to resolve using root path '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject'
[Info  - 6:29:26 PM] (19530)   No python interpreter search path
(19530) [FG] parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 3ms] (161ms)
(19530) [FG] binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/builtins.pyi (69ms)
(19530) [FG] binding: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (2ms)
[Info  - 6:29:26 PM] (19530) Background analysis(1) root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist
[Info  - 6:29:26 PM] (19530) Background analysis(1) started
(19530) Background analysis message: setConfigOptions
(19530) Background analysis message: setImportResolver
(19530) Background analysis message: ensurePartialStubPackages
(19530) Background analysis message: setTrackedFiles
(19530) Background analysis message: markAllFilesDirty
(19530) Background analysis message: setFileOpened
(19530) Background analysis message: getSemanticTokens full
(19530) [BG(1)] getSemanticTokens full at /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py ...
(19530) [BG(1)]   parsing: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (105ms)
[Info  - 6:29:26 PM] (19530) Could not resolve source for 'django.shortcuts' in file '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py'
[Info  - 6:29:26 PM] (19530)   Looking in root directory of execution environment '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject'
[Info  - 6:29:26 PM] (19530)   Attempting to resolve using root path '/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject'
[Info  - 6:29:26 PM] (19530)   No python interpreter search path
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 3ms] (148ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/builtins.pyi (50ms)
(19530) [BG(1)]   binding: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (1ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/typing.pyi [fs read 2ms] (49ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/typing.pyi (29ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (6ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/typing_extensions.pyi (3ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (11ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (4ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/types.pyi [fs read 1ms] (22ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/types.pyi (4ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (1ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/shortcuts.pyi [fs read 0ms] (4ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/shortcuts.pyi (1ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/__init__.pyi [fs read 3ms] (6ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/__init__.pyi (1ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/request.pyi [fs read 1ms] (11ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/request.pyi (2ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/io.pyi [fs read 0ms] (4ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib/io.pyi (2ms)
(19530) [BG(1)]   parsing: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/response.pyi [fs read 1ms] (7ms)
(19530) [BG(1)]   binding: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs/django-stubs/http/response.pyi (15ms)
(19530) [BG(1)] getSemanticTokens full at /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (575ms)
(19530) Background analysis message: analyze
(19530) [BG(1)] analyzing: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py ...
(19530) [BG(1)]   checking: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (14ms)
(19530) [BG(1)] analyzing: /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (15ms)
(19530) Background analysis message: getSemanticTokens range
(19530) [BG(1)] getSemanticTokens range 0:0 - 6:0 at /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/landingpage/views.py (1ms)
(19530) Background analysis message: resumeAnalysis
(19530) Loading ONNX runtime...
(19530) Loaded ONNX runtime. Creating IntelliCode session...
2023-01-30 18:29:28.691676 [I:onnxruntime:, inference_session.cc:263 operator()] Flush-to-zero and denormal-as-zero are off
2023-01-30 18:29:28.693151 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
2023-01-30 18:29:28.693906 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0
2023-01-30 18:29:28.757211 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.
2023-01-30 18:29:28.757398 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.
2023-01-30 18:29:28.773743 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0
2023-01-30 18:29:28.781553 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.
2023-01-30 18:29:28.782348 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2023-01-30 18:29:28.782718 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.
2023-01-30 18:29:28.783811 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0
2023-01-30 18:29:28.792886 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements
2023-01-30 18:29:28.796860 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59
2023-01-30 18:29:28.809380 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping
2023-01-30 18:29:28.810426 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.
2023-01-30 18:29:28.810862 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.
2023-01-30 18:29:28.899066 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors
2023-01-30 18:29:28.901440 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.
2023-01-30 18:29:28.908764 [I:onnxruntime:, inference_session.cc:271 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
2023-01-30 18:29:28.908909 [I:onnxruntime:, inference_session.cc:292 ConstructorCommon] Dynamic block base set to 0
2023-01-30 18:29:28.984291 [I:onnxruntime:, inference_session.cc:1222 Initialize] Initializing session.
2023-01-30 18:29:28.984409 [I:onnxruntime:, inference_session.cc:1259 Initialize] Adding default CPU execution provider.
2023-01-30 18:29:28.984994 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0
2023-01-30 18:29:28.985943 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.
2023-01-30 18:29:28.987115 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2023-01-30 18:29:28.987184 [I:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.
2023-01-30 18:29:28.987571 [I:onnxruntime:, reshape_fusion.cc:42 ApplyImpl] Total fused reshape node count: 0
2023-01-30 18:29:28.995392 [V:onnxruntime:, session_state.cc:1010 VerifyEachNodeIsAssignedToAnEp] Node placements
2023-01-30 18:29:28.995488 [V:onnxruntime:, session_state.cc:1013 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 59
2023-01-30 18:29:28.995889 [V:onnxruntime:, session_state.cc:66 CreateGraphInfo] SaveMLValueNameIndexMapping
2023-01-30 18:29:28.995995 [V:onnxruntime:, session_state.cc:112 CreateGraphInfo] Done saving OrtValue mappings.
2023-01-30 18:29:28.996347 [I:onnxruntime:, session_state_utils.cc:199 SaveInitializedTensors] Saving initialized tensors.
2023-01-30 18:29:29.050854 [I:onnxruntime:, session_state_utils.cc:342 SaveInitializedTensors] Done saving initialized tensors
2023-01-30 18:29:29.051324 [I:onnxruntime:, inference_session.cc:1488 Initialize] Session successfully initialized.
(19530) Created IntelliCode session.
(19530) Created IntelliCode session.
(19530) Initialize deeplearning succeeded
(19530) Initialize deeplearning succeeded
heejaechang commented 1 year ago

so. this and this show that we are not getting python search path.

[Info  - 6:29:26 PM] (19530) Search paths for /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stdlib
[Info  - 6:29:26 PM] (19530)   /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject
[Info  - 6:29:26 PM] (19530)   /Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/typings
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/typeshed-fallback/stubs/...
[Info  - 6:29:26 PM] (19530)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.1.40/dist/bundled/stubs
[Info  - 6:29:26 PM] (19530)   No python interpreter search path

hard to know why your python interpreter returns nothing for sys.path

if you run python in your venv and import sys; sys.path what does it say?

omeinusch commented 1 year ago

I wondered myself about that entry in the log. I tried afterwards to fix it with python.pythonPath in the workspace settings.json but that did not help.

In the terminal within VSCode, the last item is the correct site-packages directory:

(.venv) tjati@mbp mysuperproject % python
Python 3.11.1 (v3.11.1:a7a450f84a, Dec  6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; sys.path 
['', '/Library/Frameworks/Python.framework/Versions/3.11/lib/python311.zip', 
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11', 
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload', 
'/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject/.venv/lib/python3.11/site-packages']
heejaechang commented 1 year ago

did you make sure you are working with trusted workspace?, if you are using untrusted workspace, vscode won't give us permission to run any executable, meaning we can't run python interpreter to get sys.path

omeinusch commented 1 year ago

I understand the limitations of an untrusted workspace and verified that I have configured the folder as a trusted workspace. In addition, I added the folder again to the list of trusted workspace. I dont see any other limitations and the untrusted-badge in the bottom left isn't shown, too.

I checked with another python project I worked in the past with and have the same pylance-Error and can't remember, I had it in the past.

Please advise how to proceed. Your support is highly appreciated.

heejaechang commented 1 year ago

hmm.. I assume you checked that python path points to the right one and you don't have any custom stuff that re-write python path?

this is what we actually run to get python search path. can you run to see what you get?

[venv python path] -c 'import os, os.path, sys;normalize = lambda p: os.path.normcase(os.path.normpath(p));cwd = normalize(os.getcwd());orig_sys_path = [p for p in sys.path if p != ""];sys.path[:] = [p for p in sys.path if p != "" and normalize(p) != cwd];import sys, json;json.dump(dict(path=orig_sys_path, prefix=sys.prefix), sys.stdout)'
omeinusch commented 1 year ago

python path points to the .venv/bin/python, even ommitted, it does not work.

This is the output of the command and includes the .venv-site-packages.


{"path": ["/Library/Frameworks/Python.framework/Versions/3.11/lib/python311.zip", "/Library/Frameworks/Python.frame
work/Versions/3.11/lib/python3.11", "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload", "/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperapp/.venv/lib/python3.11/site-packages"], "prefix": "/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperapp/.venv"}
heejaechang commented 1 year ago

hmmm.. now I am not sure why you are not getting any search path..... we might need to give you some debug bits to run to see what output we get from pylance itself.

heejaechang commented 1 year ago

I made a change to Pylance so that we log more on python search path. once you install our next pylance pre-release bit (2023.2.11 - which will be most likely released tomorrow afternoon), if you enable the log, it will have new entries about python search path.

let's see what it says once you have the bits.

omeinusch commented 1 year ago

Highly appreciated the extra effort. I looo forward to try the update and post an update as soon as possible.

Just FYI: I removed the the configuration for Run/Debug as was therefore prompted to state how I want to run Debug the next time I clicked the button. I could chose Python and was afterwards prompted for Django which I confirmed and it worked seamlessly. At this part the right setup was configured by VSC.

omeinusch commented 1 year ago

The output of the log is super interesting, and I think we're close to the issue. It seems, that the path of my working directory is the issue and pylance tries to replace ~ within the path with my home path which leads to wrong paths.

(.venv) tjati@mbp mysuperproject % pwd
/Users/tjati/Library/Mobile Documents/com~apple~CloudDocs/Development/mysuperproject

This is the output of pylance, which leads to a crash of the extension. It seems I am the first to work within my "iCloud Documents" folder.


[Info  - 9:14:50 AM] (27157) Pylance language server 2023.2.11 (pyright cca7588f) starting
[Info  - 9:14:50 AM] (27157) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist
[Info  - 9:14:50 AM] (27157) Starting service instance "mysuperproject"
[Info  - 9:14:50 AM] (27157) Auto-indent enabled
[Info  - 9:14:50 AM] (27157) Starting service instance "<default>"
[Info  - 9:14:50 AM] (27157) No pyproject.toml file found.
[Info  - 9:14:50 AM] (27157) Setting pythonPath for service "<default>": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 9:14:50 AM] (27157) stubPath typings is not a valid directory.
[Info  - 9:14:50 AM] (27157) Assuming Python platform Darwin
[Info  - 9:14:50 AM] (27157) Search paths for <default>
Error: spawn /Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[Info  - 9:14:50 AM] (27157)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stdlib
[Info  - 9:14:50 AM] (27157)   typings
[Info  - 9:14:50 AM] (27157)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stubs/...
[Info  - 9:14:50 AM] (27157)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/bundled/stubs
[Info  - 9:14:50 AM] (27157) Searching for source files
[Info  - 9:14:50 AM] (27157) No source files found.
[Info  - 9:14:50 AM] Connection to server got closed. Server will restart.
[Info  - 9:14:51 AM] (27185) Pylance language server 2023.2.11 (pyright cca7588f) starting
[Info  - 9:14:51 AM] (27185) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist
[Info  - 9:14:51 AM] (27185) Starting service instance "mysuperproject"
[Info  - 9:14:51 AM] (27185) Auto-indent enabled
[Info  - 9:14:51 AM] (27185) Starting service instance "<default>"
[Info  - 9:14:51 AM] (27185) No pyproject.toml file found.
[Info  - 9:14:51 AM] (27185) Setting pythonPath for service "<default>": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 9:14:51 AM] (27185) stubPath typings is not a valid directory.
[Info  - 9:14:51 AM] (27185) Assuming Python platform Darwin
[Info  - 9:14:51 AM] (27185) Search paths for <default>
[Info  - 9:14:51 AM] (27185)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stdlib
[Info  - 9:14:51 AM] (27185)   typings
[Info  - 9:14:51 AM] (27185)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stubs/...
Error: spawn /Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[Info  - 9:14:51 AM] (27185)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/bundled/stubs
[Info  - 9:14:51 AM] (27185) Searching for source files
[Info  - 9:14:51 AM] (27185) No source files found.
[Info  - 9:14:51 AM] Connection to server got closed. Server will restart.
[Info  - 9:14:51 AM] (27189) Pylance language server 2023.2.11 (pyright cca7588f) starting
[Info  - 9:14:51 AM] (27189) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist
[Info  - 9:14:51 AM] (27189) Starting service instance "mysuperproject"
[Info  - 9:14:51 AM] (27189) Auto-indent enabled
[Info  - 9:14:51 AM] (27189) Starting service instance "<default>"
[Info  - 9:14:51 AM] (27189) No pyproject.toml file found.
[Info  - 9:14:51 AM] (27189) Setting pythonPath for service "<default>": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 9:14:51 AM] (27189) stubPath typings is not a valid directory.
[Info  - 9:14:51 AM] (27189) Assuming Python platform Darwin
[Info  - 9:14:51 AM] (27189) Search paths for <default>
[Info  - 9:14:52 AM] (27189)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stdlib
[Info  - 9:14:52 AM] (27189)   typings
[Info  - 9:14:52 AM] (27189)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stubs/...
[Info  - 9:14:52 AM] (27189)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/bundled/stubs
[Info  - 9:14:52 AM] (27189) Searching for source files
[Info  - 9:14:52 AM] (27189) No source files found.
Error: spawn /Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[Info  - 9:14:52 AM] Connection to server got closed. Server will restart.
[Info  - 9:14:52 AM] (27194) Pylance language server 2023.2.11 (pyright cca7588f) starting
[Info  - 9:14:52 AM] (27194) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist
[Info  - 9:14:52 AM] (27194) Starting service instance "mysuperproject"
[Info  - 9:14:52 AM] (27194) Auto-indent enabled
[Info  - 9:14:52 AM] (27194) Starting service instance "<default>"
[Info  - 9:14:52 AM] (27194) No pyproject.toml file found.
[Info  - 9:14:52 AM] (27194) Setting pythonPath for service "<default>": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 9:14:52 AM] (27194) stubPath typings is not a valid directory.
[Info  - 9:14:52 AM] (27194) Assuming Python platform Darwin
[Info  - 9:14:52 AM] (27194) Search paths for <default>
[Info  - 9:14:52 AM] (27194)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stdlib
[Info  - 9:14:52 AM] (27194)   typings
[Info  - 9:14:52 AM] (27194)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stubs/...
[Info  - 9:14:52 AM] (27194)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/bundled/stubs
[Info  - 9:14:52 AM] (27194) Searching for source files
[Info  - 9:14:52 AM] (27194) No source files found.
Error: spawn /Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[Info  - 9:14:52 AM] Connection to server got closed. Server will restart.
[Info  - 9:14:53 AM] (27198) Pylance language server 2023.2.11 (pyright cca7588f) starting
[Info  - 9:14:53 AM] (27198) Server root directory: /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist
[Info  - 9:14:53 AM] (27198) Starting service instance "mysuperproject"
[Info  - 9:14:53 AM] (27198) Auto-indent enabled
[Info  - 9:14:53 AM] (27198) Starting service instance "<default>"
[Info  - 9:14:53 AM] (27198) No pyproject.toml file found.
[Info  - 9:14:53 AM] (27198) Setting pythonPath for service "<default>": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"
[Warn  - 9:14:53 AM] (27198) stubPath typings is not a valid directory.
[Info  - 9:14:53 AM] (27198) Assuming Python platform Darwin
[Info  - 9:14:53 AM] (27198) Search paths for <default>
[Info  - 9:14:53 AM] (27198)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stdlib
[Info  - 9:14:53 AM] (27198)   typings
[Info  - 9:14:53 AM] (27198)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/typeshed-fallback/stubs/...
[Info  - 9:14:53 AM] (27198)   /Users/tjati/.vscode/extensions/ms-python.vscode-pylance-2023.2.11/dist/bundled/stubs
[Info  - 9:14:53 AM] (27198) Searching for source files
[Info  - 9:14:53 AM] (27198) No source files found.
Error: spawn /Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[Error - 9:14:53 AM] The Pylance server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
``
heejaechang commented 1 year ago

let me take a look

rchiodo commented 1 year ago

This issue has been fixed in prerelease version 2023.2.12, which we've just released. You can find the changelog here: CHANGELOG.md

OmarEzQED commented 8 months ago

what if I use docker and not a local enviroment. How can I solve the issue

bschnurr commented 8 months ago

please create a new issue with logs

namoninja commented 5 months ago

Hi, this still seems to be an issue.

VSCode v1.88.1 | PyLance v2024.4.1 | Interpreter is set to .venv python.

absolute path = /home/user/~testfolder/testapp log = (98763) Setting pythonPath for service "testapp": "/home/user/home/usertestfolder/testapp/venv/bin/python"

as you can see it tries to expand the ~ as a home path.

Same can be seen in OP's logs (19530) Setting pythonPath for service "mysuperproject": "/Users/tjati/Library/Mobile Documents/com/Users/tjatiapple/Users/tjatiCloudDocs/Development/mysuperproject/.venv/bin/python"

In this case there were multiple ~ in the pathname so it tried to expand it multiple times.

if I change the name of the folder it works fine.

absolute path = /home/user/testfolder/testapp log = Setting pythonPath for service "testapp": "/home/user/testfolder/testapp/venv/bin/python"

debonte commented 5 months ago

I am also able to repro this. Seems that it regressed at some point. Maybe due to the URI refactoring? It looks like the tests for this scenario were removed at some point?

KacieKK commented 4 months ago

This issue has been fixed in prerelease version 2024.5.100, which we've just released. You can find the changelog here: CHANGELOG.md