I can't seem to get my settings.json file to influence how python is invoked in VSCode when selecting "Run Code" (default hot key Ctrl + Alt + N), my user settings.json is as follows:
{
"python.pythonPath": "/usr/bin/python3",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.jediEnabled": true,
"editor.minimap.enabled": true,
"editor.multiCursorModifier": "ctrlCmd",
"workbench.tree.indent": 24,
"workbench.startupEditor": "untitled",
"workbench.settings.editor": "json",
"workbench.settings.openDefaultKeybindings": false,
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": false,
"explorer.confirmDragAndDrop": false,
"python.linting.enabled": true,
"python.languageServer": "Jedi",
}
yet when I run my python file, not debug it, it is showing:
[Running] python -u "path/to/file.py"
when I am expecting (as I set python.pythonPath in settings.json):
[Running] /usr/bin/python3 -u "path/to/file.py"
Why is my settings.json file key python.pythonPath having no effect on how my code is invoked?
Among other important reasons, my python code doesn't even run as python invokes python 2 on my machine when my code is written in python 3.
VSCode version:
Version: 1.47.3
Commit: 91899dcef7b8110878ea59626991a18c8a6a1b3e
Date: 2020-07-23T15:51:39.791Z (1 mo ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.15.0-112-generic
From vscode-python-DeprecatePythonPath, python.pythonPath setting is being removed from all 3 scopes - User, workspace, workspace folder. The path to the workspace interpreter will now be stored in VS Code’s persistent storage instead of the settings.json file. That's why your setting has no effect on code execution path. You can change the value stored in workspace settings using Python: Select Interpreter command, or add the setting in User settings.json:
"python.defaultInterpreterPath":
Related
I set my settings.json to Anaconda python 3.6.10 but Code runner still runs the code in 3.7.6. I used OS to check and in fact, that is true. I then used terminal to run my file and it is Python 3.6.10. How can I change my Code Runner to run at whatever version I set in the .vscode settings.json file?
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
With this it should follow the anaconda settings in VS Code.
I've installed most popular Python extensions in vscode. So I can do shift+enter to execute some selected code into a python terminal.
This uses /usr/bin/python3 as default. I would like to use IPython3 instead. However, I don't find such settings in settings.json.
How can I configure the default Python terminal in vscode?
1.The reason for "I can do shift+enter to execute some selected code into a python terminal." is that "shift+enter" is the default shortcut key of VSCode, and the command it executes is "python.execSelectionInTerminal":
{ "key": "shift+enter", "command": "python.execSelectionInTerminal",
"when": "editorTextFocus && !findInputFocussed && !jupyter.ownsSelection && !replaceInputFocussed && editorLangId == 'python'" },
2.Set the default terminal to ipython in VSCode, please use "ipython.exe" to execute the file in settings.json: for example:
"terminal.integrated.shell.windows": "D:\\Users\\...\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\ipython.exe",
Use:
Open a file with the suffix .ipynb and vs code will do the rest
Here is my VS code infor:
Version: 1.43.2 (user setup)
Commit: 0ba0ca52957102ca3527cf479571617f0de6ed50
Date: 2020-03-24T07:38:38.248Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.17763
My python path is here:
/auto/energymdl2/anaconda3/envs/commod_py3_20200921/bin/python
But VS codes keeps saying Select Python Interpreter in the status bar even after I selected.
But when I try to select, it says it is already being selected. At moment, due to this, I am unable to use Python linter Flake8.
When I check the console log. I got the following.
Error Python Extension: 2020-09-23 05:02:01: Failed to parse interpreter information for /auto/energymdl2/anaconda3/envs/commod_py3_20200921/bin/python,/home/test/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/pyvsc-run-isolated.py,/home/test/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/interpreterInfo.py stderr: Error in sitecustomize; set PYTHONVERBOSE for traceback:ModuleNotFoundError: No module named 'sdlc'
But when I go into Python and import sdlc. I am able to.
Python/iPython path:
/auto/energymdl2/anaconda3/envs/commod_py3_20200921/bin/python
Here is what I have in my setting.json
{
"python.linting.pycodestyleEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.linting.flake8Args": [
"--ignore=W605",
"--ignore=W503",
"--ignore=W605",
"--max-line-length=120"
],
"python.linting.banditEnabled": false,
"python.pythonPath": "/auto/energymdl2/anaconda3/envs/commod_py3_20200921/bin/python",
// "python.condaPath": "/auto/energymdl2/anaconda3/envs/commod_py3_20200727/bin/python"
}
It turned out that there is some logic goes into $your_conda_env_path/lib/python3.6/site-packages/sitecustomize.py that imports user-defined packages in working repo. But the working directory env variable was not set properly. I created a .env file under repo root dir and added relevant env variables. It resolved the issue.
So in fact all the conda envs were detected. It is just when it tries to load them, it hits ModuleNotFoundError.
I have Visual Studio Code installed with the Python extension. When I try to open a .py or .ipynb file from the Windows File Explorer with VSCode, nothing opens and I get the windows "ding" sound instead (the same sound you get when a popup prevents you from interacting with other apps until you dismiss the popup). I tried user settings with and without file.associations, but either case did not work. Everything seems to work fine when from VSCode I choose File>>Open Folder and then browse to the .py or .ipynb file. Any idea why this is happening?
{
"python.dataScience.sendSelectionToInteractiveWindow": true,
"python.testing.unittestEnabled": true,
"editor.renderWhitespace": "selection",
"editor.renderControlCharacters": false,
"window.zoomLevel": -1,
"workbench.colorTheme": "Visual Studio Dark",
"python.linting.pycodestyleCategorySeverity.E": "Information",
"python.linting.pycodestyleCategorySeverity.W": "Information",
"editor.minimap.showSlider": "always",
"editor.minimap.maxColumn": 100,
"python.linting.pycodestyleEnabled": true,
"editor.accessibilitySupport": "off",
"[xml]": {},
"python.dataScience.askForKernelRestart": false,
"git.enableSmartCommit": true,
"[jsonc]": {},
"editor.minimap.size": "fill",
"editor.tabSize": 2,
"python.dataScience.textOutputLimit": 0,
"files.associations": {
"*.py": "python",
"*.ipynb": "python",
"*.pyt": "python"
},
"python.pythonPath": "c:\\my\\env\\Python.exe",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
}
I don't believe that shell file associations are set up with VS Code by default. files.associations setting is just to tie file extensions to the type of code inside visual studio code itself. If you right-click on a .py file do you see an option Open With=>Visual Studio Code? That option should be available to open it in VS Code.
If you want that to be default you can right click it in the shell and pick Open With=>Choose another app to select VSCode as the default app to open that item with.
$ where python
C:\Users\Idan\AppData\Local\Programs\Python\Python38\python.exe
C:\Users\Idan\AppData\Local\Microsoft\WindowsApps\python.exe
The Error:
Idan#DESKTOP-A16D3QA MINGW64 ~/Desktop/ttt
$ C:\Users\Idan\AppData\Local\Programs\Python\Python38\python.exe -u "c:\Users\Idan\AppData\Local\Programs\Python\Python38\s.py"
bash: C:UsersIdanAppDataLocalProgramsPythonPython38python.exe: command not found
deafault settings json file:
// Path to the pipenv executable to use for activation.
"python.pipenvPath": "pipenv",
// Path to the poetry executable.
"python.poetryPath": "poetry",
// Path to Python, you can use a custom version of Python by modifying this setting to include the full path.
"python.pythonPath": "python",
settings.json
What I tried to do (integrate pipenv instead of venv):
"python.pythonPath": "C:\\Users\\Idan\\AppData\\Local\\Programs\\Python\\Python38\\python.exe",
"python.pipenvPath": "pipenv",
"python.testing.pytestEnabled": true,
"python.venvPath": "C:\\Users\\Idan\\.virtualenvs",
],
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
},
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
other configuration I tried resulting in same error:
"python.venvPath": "C:\\Users\\Idan\\.virtualenvs",
// this is the actual locatation
// of the pythonpath C:\\Users\\Idan\\.virtualenvs\\Idan-iyfIpKqV\Scripts\python.exe
"python.pythonPath": "$venvPath\\pipenvPath\\Scripts\\python.exe",
//"python.pythonPath": "$venvPath\\ENV-NAME\\Scripts\\python.exe",
This is the full settings.json I have:
https://gist.github.com/IdanBanani/0d562770f14f3098debb6e1d47179e3f
previously, combining lines from these two sources was working (venv):
https://github.com/CoreyMSchafer/dotfiles/blob/master/settings/VSCode-Settings.json
https://github.com/xames3/xai_django/blob/bcaf169837d484d0bcf8686c18dc0529d1469034/.vscode/settings.json
but I tried to replace to pipenv, and might try in the future to automatically set it to create and activate the virtualenv
(pipenv install, pipenv shell) but not sure how easy it is
Also: I had to remove these lines of the thefuck project from .bashrc file because of error messages in the output console(maybe the installation/pip package got removed)
eval $(thefuck --alias)
# You can use whatever you want as an alias, like for Mondays:
eval $(thefuck --alias FUCK)
This is my current fix, but I don't think it's good enough for the generic case
Why does it keep creating the virtual env in a constant folder name Idan-iyfIpKqV?
"python.venvPath": "C:/Users/Idan/.virtualenvs",
"python.pythonPath": "C:/Users/Idan/.virtualenvs/Idan-iyfIpKqV/Scripts/python.exe",