Closed RishabhMalviya closed 3 years ago
Same problem here. I also tried to create a new project, initialize venv inside cwd and reopen folder and now I get the message:
I installed Code and Python extension inside VM to eliminate problem with my configuration and I get the same type of error. Although when I hit run it finds somehow path to python.
Version: 1.51.1 Date: 2020-11-12T10:54:25.653Z Electron: 9.3.4 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Linux x64 5.8.18-1-MANJARO Python: 3.8.6
Also same here!
OS: Linux x64 5.9.8-arch1-1 Python: 3.8.6 VSC Version: 1.50.1 Electron: 9.3.4 Chrome: 83.0.4103.122 Node.js: 12.14.1
ah also, looking at other issues & releases, according to a recent release, and issue #12462, this has been changed. I'm not quite sure about how this affects things, but it is a possibility.
Hello @RishabhMalviya and @ShadiestGoat, thank you for reaching out.
The python.pythonPath
setting in settings.json
only accepts the path to the Python interpreter, or the path to a folder containing the Python interpreter (settings reference).
If you want to specify extra paths like your workspace root, you should use the PYTHONPATH
environment variable, which you can specify in a .env
file, or via the OS-specific terminal.integrated.env.*
setting (see this paragraph about the use of the PYTHONPATH
environment variable).
@kimadeline Thanks for the helpful reply.
As explained in the links you sent, I added the following to my .env
file:
PYTHONPATH="/app:${env:PYTHONPATH}"
(I'm working inside a Docker container, and the absolute path /app
is where all my code lives).
And following the steps taken by the OP in #12085, I added the terminal.integrated.env.*
settings in my settings.json
as follows:
{
"python.pythonPath": "/usr/local/bin/python",
"python.autoComplete.extraPaths": ["/app"],
"terminal.integrated.env.linux": {
"PYTHONPATH": "/app:${env:PYTHONPATH}"
},
"terminal.integrated.env.osx": {
"PYTHONPATH": "/app:${env:PYTHONPATH}"
},
"terminal.integrated.env.windows": {
"PYTHONPATH": "/app:${env:PYTHONPATH}"
}
}
Auto-complete and debugging are working as expected now!
But for some reason, the linter continues to insist that the imports from /app
are incorrect. As a result, my Problems pane is almost always full.
Is linting not part of the core VSCode Python extension?
Hi @RishabhMalviya,
Linting is supported by the extension, although you'll have to install your own linter. Please open a separate issue since it is unrelated to what was initially reported, and specify there which linter you use as well.
Thanks!
Environment data
python.languageServer
setting: JediExpected behaviour
The Python Interpreter should be picked up from the
"python.pythonPath"
key insettings.json
.Also, one should be able to specify multiple paths in the
"python.pythonPath"
insettings.json
. In particular, I would like to point to:This is to ensure linting and auto-complete to work properly:
(In the case of multiple paths, the Python interpreter should be picked up from the first path.)
Actual behaviour
Every time I open VSCode or I try to run/debug my Python files, I am shown the following prompt: "You need to select a Python interpreter before you start debugging."
When I do so (selecting
/usr/local/bin/python
from the drop-down), it overwrites thesettings.json
file and removes the${workspaceFolder}
:This causes red linting to begin showing up in my code, because I am performing certain imports from the root of my working directory (and it has been removed from the
settings.json
).Steps to reproduce:
API_TOKEN
in line 13 on the.env
file:docker-compose up -d model-dev
. Wait for the container to come up."Remote-Containers: Attach to Running Container"
, and attach to themodel-dev
container you brought up in the previous step./app
in the VSCode instance.ms-python.python
) Extension is installed. If not, install it. You may also get a prompt to"install Linter pylint"
. Install it as well.app.py
and try to run it.Select Python Interpreter
, and choose the interpreterPython 3.9.0 64-bit /usr/local/bin/python
.app.py
, and there should be corresponding entries in theProblems
panel on the bottom.settings.json
back to the original:app.py
again. You'll be forced to select a Python interpreter again.Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)``` XXX ```