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.
Related
I have a python library in github I want to debug. The library has setup.py as well as a pip released package. So I can install this module using either pip install git-sim or python3 setup.py install.
This module adds a command to the path and I can execute in terminal with git-sim .
Main Problem: I want to clone the github repo and open vscode inside the cloned repo and debug the code getting executed while I am running the command from the terminal. The breakpoints should hit the file inside the repo.
Link to the github Repo: https://github.com/initialcommit-com/git-sim
I went searching with these requirements. Best I could come up so far is
An edit mode in setup.py which can be started by pip install -e . . While I ran this command and was successful I did not see a way to debug it.
How do we debug a module in Vscode? Give this code in launch.json
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "git-sim",
"justMyCode": false,
}
But while I am running this I am getting an error, no module named git-sim even though the same command works outside the debugger in the terminal. i.e both git-sim and python3 -m git_sim
Any suggestion of where I maybe going wrong? Or if there is some alternative option I have not considered
Found the issue. I made a mistake in assuming the terminal command git-sim and the actual python -m git_sim were same.
Module Name and Terminal commands are different. So if we modify launch config from "module":"git-sim" to "module":"git_sim" it works. Modified config given below:
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "git_sim",
"justMyCode": false,
}
Can't open an issue on github atm because I get a 500 error for 30minutes now when trying to create the issue.
VS Code Version: 1.59.0
OS Version: Windows 10 Professional 64bit 21H2 19043.1151
Steps to Reproduce:
Clean install of VS Code
Clean install of Python 3.9.6
pip install black (version 21.7b0)
Install VS Code extension "Python"
in VS Code set formatter to "black"
open project folder
open test.py file from project
save unformatted file with CTRL+S --> "Formatting with black" appears in the bottom corner but nothing happens
user settings.json
{
"python.formatting.provider": "black",
"editor.formatOnSave": true
}
workspace settings.json
{
"python.formatting.provider": "black"
}
It works when I call "black" via CMD --> "black test.py"
reformatted test.py
All done! ✨ 🍰 ✨
1 file reformatted.
Already tried reinstalling VS Code / Python and restarting the PC???
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
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":
$ 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",