I'm using VS code as my IDE for Python (anaconda environment). So I configured cmder as my terminal and I tried to test a simple print statement by clicking on the run button (green triangle). I got the following error:
My JSON settings looks like this:
{
"terminal.integrated.shell.windows": "Cmder.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "C:\\Users\\EK\\Cmder.exe"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.Cmder"
],
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe",
"atomKeymap.promptV3Features": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.formatOnPaste": true,
"kite.showWelcomeNotificationOnStartup": false,
"workbench.colorCustomizations": {
"terminal.background": "#1D2021",
"terminal.foreground": "#09c0f8",
"terminalCursor.background": "#A89984",
"terminalCursor.foreground": "#A89984",
"terminal.ansiBlack": "#1D2021",
"terminal.ansiBlue": "#0D6678",
"terminal.ansiBrightBlack": "#665C54",
"terminal.ansiBrightBlue": "#0D6678",
"terminal.ansiBrightCyan": "#8BA59B",
"terminal.ansiBrightGreen": "#95C085",
"terminal.ansiBrightMagenta": "#8F4673",
"terminal.ansiBrightRed": "#FB543F",
"terminal.ansiBrightWhite": "#FDF4C1",
"terminal.ansiBrightYellow": "#FAC03B",
"terminal.ansiCyan": "#fbfdfc",
"terminal.ansiGreen": "#95C085",
"terminal.ansiMagenta": "#8F4673",
"terminal.ansiRed": "#FB543F",
"terminal.ansiWhite": "#A89984",
"terminal.ansiYellow": "#FAC03B"
},
"workbench.colorTheme": "Monokai Dimmed",
"workbench.editor.decorations.colors": true,
"workbench.preferredHighContrastColorTheme": "Visual Studio Light",
"python.formatting.provider": "none",
"terminal.integrated.automationShell.linux": "",
"terminal.integrated.scrollback": 100000,
"workbench.editorAssociations": [
{
"viewType": "jupyter.notebook.ipynb",
"filenamePattern": "*.ipynb"
}
],
"terminal.integrated.env.windows": {}
}
I have no clue why things are going wrong? Can someone please help me with this?
Please find the absolute path of the executable file of "cmder", and use this path in "settings.json":
"settings.json":
"terminal.integrated.shell.windows": "..:\\cmder\\Cmder.exe",
Run:
In addition, please check whether the "cmder" terminal can be used outside of VS Code.
Reference: Integrated Terminal in VS Code.
Related
I am using Visual Studio, python3.9 and pytest. I used to put __init__.py files in the project __tests__ folders that contained my unit test files. Then I encountered a failed unit test that was caused by the presence of an __init__.py file. The reason for the failure are in the links below. How do I get the test discovery tool (beaker symbol) in VScode to discover my unit tests without using __init__.py files?
pytest cannot import module while python can
pytest and why avoid init file
settings.json:
{
"python.defaultInterpreterPath": "venv/bin/python",
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*tests.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true,
"python.linting.enabled": true,
"python.linting.pycodestyleEnabled": true,
"python.linting.pycodestyleArgs": [
"--line-length",
"120"
],
"python.formatting.provider": "autopep8",
"editor.formatOnPaste": false,
"editor.formatOnSaveMode": "file",
"python.formatting.autopep8Args": [
"--max-line-length",
"120"
],
"git.ignoreLimitWarning": true,
}
the context
I am debugging an application using Visual Studio Code (VSCode).
The application relies mainly on https://plot.ly, https://palletsprojects.com/p/flask, https://pandas.pydata.org/ and https://numpy.org/
Breakpoints ARE NOT hit!
The breakpoints ARE NOT hit when I am using the launch.json (See [1])
I can debug with this launch.json (See [2]) but the debugger does not stops at the breakpoint !
I would like VSCode to stop on my breakpoints when necessary
**What is the correct configuration for launch.json to hit the breakpoints? **
Thank you for the time you are investing helping me!
the hierarchy of the project
launch.json
index.py See [4]
app.py See [3]
pages
index.py
transactions.py
launch.json is described here below [1]
the issue : Error: module 'index' has no attribute 'app.server'
The Error message is displayed after clicking on 'Start debugging > F5' = Error: module 'index' has no attribute 'app.server'
I tried dozens of ways to set the "FLASK_APP": "index:app.server" but they generate diverse error messages :
"FLASK_APP": "index:app.server" generates this error Error: A valid Flask application was not obtained from "index:app".
"FLASK_APP": "index.py" generates this error Error: Failed to find Flask application or factory in module "index". Use "FLASK_APP=index:name to specify one.
for information : gunicorn command (working)
here is a command available in azure-pipelines.yml running the plotly app :
gunicorn --bind=0.0.0.0 --timeout 600 index:app.server
attached files
[1] launch.json - non working
{
"version": "0.2.0",
"configurations": [
{
"name": "Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "index:app.server",
"FLASK_ENV": "development",
"FLASK_DEBUG": "1",
"FLASK_RUN_PORT": "8052"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
[2] launch.json - working but breakpoints are not hit
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}\\index.py",
"console": "integratedTerminal"
}
]
}
[3] webapp.py
# -*- coding: utf-8 -*-
import dash
app = dash.Dash(
__name__, meta_tags=[{"name": "viewport",
"content": "width=device-width, initial-scale=1"}]
)
server = app.server
app.config.suppress_callback_exceptions = True
index.py - root of the application
# -*- coding: utf-8 -*-
import dash_html_components as html
import dash_core_components as dcc
from webapp import app
from dash.dependencies import Input, Output
from pages import (
transactions, index)
# Describe the layout/ UI of the app
app.layout = html.Div([
dcc.Location(id="url", refresh=False),
html.Div(id="page-content")
])
# Update page
#app.callback(Output("page-content", "children"),
[Input("url", "pathname")])
def display_page(pathname):
if pathname == "/dash/index":
return index.layout
if pathname == "/dash/transactions":
return transactions.layout
else:
return index.layout
if __name__ == "__main__":
app.run_server(debug=True, port=8051)
Your [1] example isn't working because you set FLASK_APP to index:app.server which tries to find an attribute named app.server on the index module. Attribute names can't have a dot (you can verify this by importing that module and trying out getattr(index, "app.server")). You should be able to make FLASK_APP simply say index to have it work.
See the Flask documentation on app discovery for more details.
I created an exe file using py2exe(that contains media i.e images).it works fine on the computer i created the exe,but not on other computers. It raises a 'Failed to execute script' error.
you must include your file to build:
Mydata_files = [('images', ['c:/path/to/image/image.png'])]
setup(
console = ['XXXXX'],
data_files = Mydata_files,
options = {
"py2exe": {
"unbuffered": True,
"skip_archive": True,
"optimize": 2
}
}
check official site
I am trying to debug a custom management command using Visual Studio Code.
For this I have gone through the official VS Code tutorials for working with Python and Django, and I have managed to get debugging to work while following these tutorials.
VS Code Python tutorial /
VS Code Django tutorial
The problem is that for a Python script (no Django), the debugger works because I run a specific file (by pressing f5) while the file's tab is open. Django debugging works because VS Code knows when a browser request causes my Django app to hit a break-point I entered in VS Code.
But a custom management command is run differently. For this I type the following in the console:
python manage.py name_of_management_command
How do I debug this in VS Code?
While writing this question I came up with a solution myself.
In the VS Code launch.json file (which contains the settings for the VS Code Django debugger) contains the following entry, by default:
"args": ["runserver", "--noreload", "--nothreading"]
I changed this to:
"args": ["name_of_management_command"]
Then start the debugger (press f5), and I am debugging my custom management command
Rik's answer is correct, but requires changing the launch config for every management command, or creating multiple launch config entries.
To create one entry that can debug all management commands, even the ones you still have to write, add the following config to your launch.json:
{
"name": "Django MGMT Command",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"${fileBasenameNoExtension}"
]
}
This works because the name of the management command is the name of the file in which it's defined, without the .py extension. Or ${fileBasenameNoExtension} for short.
See https://code.visualstudio.com/docs/editor/variables-reference for other variables you can use in your launch config.
#Rik and #jrial are missing an important argument, which is justMyCode, suppose you want to do a custom command that use startprojectapp and you want to see the code behind it to understand how to pass the arguments. You need to specify that argument for being able to enter there.
Also, I prefer to select the custom command from a list, instead of having to create one configuration to each file (#Rik solution), or require having the file with focus (#jrial solution).
A complete configuration can be found here.
Configuration to debug any command added to option list:
{
"name": "Django Command",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"${input:variableID}",
"restaurants"
],
"justMyCode": false
}
],
"inputs": [{
"id": "variableID",
"description": "Select client or server",
"type": "pickString",
"options": ["createsuperuser", "startapp", "A CUSTOM COMMAND"],
"default": "createsuperuser"
}]
Configuration to debug the open command file: (#jrial solution modified)
{
"name": "Django Current Custom Command",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"${fileBasenameNoExtension}"
],
"justMyCode": false
}
if you don't want to go through third party libraries code, omit the variable.
Configuration to debug the open specific custom_command.py file:(#Rik solution modified)
{
"name": "Django Current Custom Command",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"custom_command",
"THIS CAN BE A REQUIRED ARGUMENT",
],
"justMyCode": false
}
I'm trying to execute a Python script via CGI. There is no problem with the execution of the script. It's the output or display where I am not getting the desired format. I'm running this CGI script with Apache2.
/usr/lib/cgi-bin/info.cgi:
#!/usr/bin/python
print "content-type: text/html\n\n";
import json
from napalm import get_network_driver
driver = get_network_driver('ios')
hub2 = driver('10.0.0.120', 'admin', 'admin')
hub2.open()
ios_output = hub2.get_facts();
print json.dumps(ios_output, indent=5)
hub2.close()
Output looks like this:
{ "os_version": "Linux Software (ADVENTERPRISEK9-M), Version 15.5(3)S3, SOFTWARE", "uptime": 10080, "interface_list": [ "Ethernet0/0", "Ethernet0/1", "Ethernet0/2", "Ethernet0/3" ], "vendor": "Cisco", "serial_number": "67109072", "model": "Unknown", "hostname": "R13", "fqdn": "R13.lab1.com" }
But the desired output after running this script via CLI should look like this:
"os_version": "Linux Software (ADVENTERPRISEK9-M), Version 15.5(3)S3,
SOFTWARE",
"uptime": 10920,
"interface_list": [
"Ethernet0/0",
"Ethernet0/1",
"Ethernet0/2",
"Ethernet0/3"
],
"vendor": "Cisco",
"serial_number": "67109072",
"model": "Unknown",
"hostname": "R13",
"fqdn": "R13.lab1.com"
Any suggestions how to get the desired output while executing info.cgi?
Fix
Changed the content type "/Json"