Debug Python module using VS Code by pressing F5
up vote
0
down vote
favorite
My project structure is as follows:
Project Folder
--setup.py
----Module Folder
------ __init__.py
------ __main__.py
My __main__.py
file contains the entry point to my application and the setup file is configured like this:
from setuptools import setup
setup(name='my_project',
version='0.1.0',
packages=['my_project'],
entry_points={
'console_scripts': [
'my_project= my_project.__main__:main'
]})
This means I can run my code without the debugger attached using:
python -m my_project
I've tried debugging using VS Code by navigating to my __main__.py
file and pressing F5 to run but this doesn't work and throws an exception. How do I configure Visual Studio Code to run this module in debug mode?
Also how do I ensure the program also runs the module and not the file I am looking at when I press F5?
python visual-studio-code vscode-settings
add a comment |
up vote
0
down vote
favorite
My project structure is as follows:
Project Folder
--setup.py
----Module Folder
------ __init__.py
------ __main__.py
My __main__.py
file contains the entry point to my application and the setup file is configured like this:
from setuptools import setup
setup(name='my_project',
version='0.1.0',
packages=['my_project'],
entry_points={
'console_scripts': [
'my_project= my_project.__main__:main'
]})
This means I can run my code without the debugger attached using:
python -m my_project
I've tried debugging using VS Code by navigating to my __main__.py
file and pressing F5 to run but this doesn't work and throws an exception. How do I configure Visual Studio Code to run this module in debug mode?
Also how do I ensure the program also runs the module and not the file I am looking at when I press F5?
python visual-studio-code vscode-settings
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My project structure is as follows:
Project Folder
--setup.py
----Module Folder
------ __init__.py
------ __main__.py
My __main__.py
file contains the entry point to my application and the setup file is configured like this:
from setuptools import setup
setup(name='my_project',
version='0.1.0',
packages=['my_project'],
entry_points={
'console_scripts': [
'my_project= my_project.__main__:main'
]})
This means I can run my code without the debugger attached using:
python -m my_project
I've tried debugging using VS Code by navigating to my __main__.py
file and pressing F5 to run but this doesn't work and throws an exception. How do I configure Visual Studio Code to run this module in debug mode?
Also how do I ensure the program also runs the module and not the file I am looking at when I press F5?
python visual-studio-code vscode-settings
My project structure is as follows:
Project Folder
--setup.py
----Module Folder
------ __init__.py
------ __main__.py
My __main__.py
file contains the entry point to my application and the setup file is configured like this:
from setuptools import setup
setup(name='my_project',
version='0.1.0',
packages=['my_project'],
entry_points={
'console_scripts': [
'my_project= my_project.__main__:main'
]})
This means I can run my code without the debugger attached using:
python -m my_project
I've tried debugging using VS Code by navigating to my __main__.py
file and pressing F5 to run but this doesn't work and throws an exception. How do I configure Visual Studio Code to run this module in debug mode?
Also how do I ensure the program also runs the module and not the file I am looking at when I press F5?
python visual-studio-code vscode-settings
python visual-studio-code vscode-settings
asked Nov 10 at 0:50
James Mundy
1,80922444
1,80922444
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
After some research I've found a solution:
- Navigate to the top right section in the debug menu and click the cog to create a
launch.json
file for this project. This will be used to configure VS Code.
- If there isn't one already a
launch.json
file be created, into it paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}",
"module": "my_project",
"cwd": "${workspaceRoot}",
}
]
}
I found this code here: https://github.com/DonJayamanne/pythonVSCode/issues/518#issuecomment-260838308
- Just using this answer didn't work for me though and I got the error:
No module named my_project
but I found this answer: https://github.com/DonJayamanne/pythonVSCode/issues/826
In it the final comment tells you add the following to the config.
"env": {"PYTHONPATH":"${workspaceRoot}"},
This fixes the error and now you can press F5 and your module will be debugged.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
After some research I've found a solution:
- Navigate to the top right section in the debug menu and click the cog to create a
launch.json
file for this project. This will be used to configure VS Code.
- If there isn't one already a
launch.json
file be created, into it paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}",
"module": "my_project",
"cwd": "${workspaceRoot}",
}
]
}
I found this code here: https://github.com/DonJayamanne/pythonVSCode/issues/518#issuecomment-260838308
- Just using this answer didn't work for me though and I got the error:
No module named my_project
but I found this answer: https://github.com/DonJayamanne/pythonVSCode/issues/826
In it the final comment tells you add the following to the config.
"env": {"PYTHONPATH":"${workspaceRoot}"},
This fixes the error and now you can press F5 and your module will be debugged.
add a comment |
up vote
0
down vote
accepted
After some research I've found a solution:
- Navigate to the top right section in the debug menu and click the cog to create a
launch.json
file for this project. This will be used to configure VS Code.
- If there isn't one already a
launch.json
file be created, into it paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}",
"module": "my_project",
"cwd": "${workspaceRoot}",
}
]
}
I found this code here: https://github.com/DonJayamanne/pythonVSCode/issues/518#issuecomment-260838308
- Just using this answer didn't work for me though and I got the error:
No module named my_project
but I found this answer: https://github.com/DonJayamanne/pythonVSCode/issues/826
In it the final comment tells you add the following to the config.
"env": {"PYTHONPATH":"${workspaceRoot}"},
This fixes the error and now you can press F5 and your module will be debugged.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
After some research I've found a solution:
- Navigate to the top right section in the debug menu and click the cog to create a
launch.json
file for this project. This will be used to configure VS Code.
- If there isn't one already a
launch.json
file be created, into it paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}",
"module": "my_project",
"cwd": "${workspaceRoot}",
}
]
}
I found this code here: https://github.com/DonJayamanne/pythonVSCode/issues/518#issuecomment-260838308
- Just using this answer didn't work for me though and I got the error:
No module named my_project
but I found this answer: https://github.com/DonJayamanne/pythonVSCode/issues/826
In it the final comment tells you add the following to the config.
"env": {"PYTHONPATH":"${workspaceRoot}"},
This fixes the error and now you can press F5 and your module will be debugged.
After some research I've found a solution:
- Navigate to the top right section in the debug menu and click the cog to create a
launch.json
file for this project. This will be used to configure VS Code.
- If there isn't one already a
launch.json
file be created, into it paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}",
"module": "my_project",
"cwd": "${workspaceRoot}",
}
]
}
I found this code here: https://github.com/DonJayamanne/pythonVSCode/issues/518#issuecomment-260838308
- Just using this answer didn't work for me though and I got the error:
No module named my_project
but I found this answer: https://github.com/DonJayamanne/pythonVSCode/issues/826
In it the final comment tells you add the following to the config.
"env": {"PYTHONPATH":"${workspaceRoot}"},
This fixes the error and now you can press F5 and your module will be debugged.
answered Nov 10 at 0:50
James Mundy
1,80922444
1,80922444
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235050%2fdebug-python-module-using-vs-code-by-pressing-f5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown