Directly run a module with relative imports inside a package
See original GitHub issueThe python interpreter got the -m option which allows to directly run a module inside a package . Would be great if PTVS implemented the same so that we can just click on any file inside a package and run/debug it directly.
startapp.py
pkg/
__init__.py
components/
core.py
__init__.py
tests/
core_test.py
__init__.py
To give a quick example. Let’s say we want to run core.py. In PTVS I have to set startapp.py as my start-up script which then in turn imports pkg.components and then runs core.py.
But on the command line with “python -m pkg.components.core” it can be run directly. So wouldn’t it be great if PTVS supported this as well so we don’t get anymore “ValueError: Attempted relative import in non-package” errors?
Thanks! Patrick
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
python - Relative imports for the billionth time
Relative imports use the module's name to determine where it is in a package. When you use a relative import like from .....
Read more >Absolute vs Relative Imports in Python
A relative import specifies the resource to be imported relative to the current location—that is, the location where the import statement is. There...
Read more >Relative Imports in Python 3
Relative imports in Python 3 are a way of importing modules and packages that are related to the current module or package.
Read more >Absolute and Relative Imports in Python
Relative import specifies an object or module imported from its current location, that is the location where import statement resides. There two ...
Read more >5. The import system — Python 3.11.4 documentation
The import statement combines two operations; it searches for the named module, then it binds the results of that search to a name...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, Do you have an ETA for this improvement ? Python 3 forces usage of a new standard notation (https://www.python.org/dev/peps/pep-0328/). We cannot use PTVS in this case. Regards, Bertrand
@greazer why was this closed without a comment?