Questions tagged [runpy]
31 questions
33
votes
4 answers
nightmare with relative imports, how does pep 366 work?
I have a "canonical file structure" like that (I'm giving sensible names to ease the reading):
mainpack/
__main__.py
__init__.py
- helpers/
__init__.py
path.py
- network/
__init__.py
clientlib.py
server.py
-…

pygabriel
- 9,840
- 4
- 41
- 54
19
votes
5 answers
how to succesfully compile python 3.x
Upon attempting to compile python 3.7 I hit Could not import runpy module:
jeremyr@b88:$ wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
....
jeremyr@b88:~/Python-3.7.3$ ./configure --enable-optimizations …

jeremy_rutman
- 3,552
- 4
- 28
- 47
11
votes
4 answers
How to execute another python script from your script and be able to debug?
You have wrapper python script that is calling another python script, currently using os.system('python another.py some-params').
You want to be able to debug both scripts and if you use os.system() you'll loose the debugger, so it does make sense…

sorin
- 161,544
- 178
- 535
- 806
10
votes
2 answers
Is there a way to pass flags to runpy?
I am looking for a way to pass miscellaneous options using runpy or other tools.
In particular, I would like to get the output of an optimized python script in another non-optimized python script.
python -O tobeoptimized.py
I have tried using…

G M
- 20,759
- 10
- 81
- 84
8
votes
3 answers
Unit testing __main__.py
I have a Python package (Python 3.6, if it makes a difference) that I've designed to run as 'python -m package arguments' and I'd like to write unit tests for the __main__.py module. I specifically want to verify that it sets the exit code…

Curtis Pew
- 107
- 1
- 7
7
votes
7 answers
Python IDLE: Run main?
I'm in IDLE:
>>> import mymodule
>>> # ???
After importing a module with:
if __name__ == '__main__':
doStuff()
How do I actually call main from IDLE?

Nick Heiner
- 119,074
- 188
- 476
- 699
3
votes
1 answer
How do closures work in runpy?
I get unexpected behaviour when I try to run methods defined in a file loaded using the runpy module. The methods do not see any variables (including imported modules) defined outside of that method. Here is how I am doing it:
#test.py
import…

david4dev
- 4,854
- 2
- 28
- 35
3
votes
1 answer
what is python runpy module?
I was wondering the purpose of runpy module in Python and how does it help in day to day development of the Python user community?
Can someone please explain the necessity, usage and advantages of runpy module in python?

thirstylad
- 357
- 5
- 12
2
votes
1 answer
python runpy.run_module exit code
Is it possible to get the exit code from a module called through runpy.run_module()?
I wish to replace my
exit_code = subprocess.call('py -m mymodule')
with
runpy.run_module('mymodule')
and still get the exit_code value.
Where mymodule…

Kees Valkhof
- 61
- 8
1
vote
2 answers
How can I prevent cached modules/variables when using runpy in pytest tests?
(Preface: This is a toy example to illustrate an issue that involves much larger scripts that use a ton of modules/libraries that I don't have control over)
Given these files:
# bar.py
barvar = []
def barfun():
barvar.append(1)
#…

omasoud
- 411
- 5
- 11
1
vote
0 answers
How to execute a file from another file with if __name__ == '__main__' for using multiprocessing
I am currently trying to parallelize a piece of code that trains a neural network with pytorch. For that I want to use the multiprocessing library. I now want to use a code ensemble of the following structure:
test1.py file:
import…

user19209602
- 11
- 2
1
vote
0 answers
Could not install module (runpy issue)
When trying to install a Python module on the Qualcomm® QCS610, some error messages occur. Python3 is used and the following commands are tried:
Python3 -m pip install tensorflow
**python3 -m pip install tflite **
The same error message comes up no…

Ahmet Deniz
- 11
- 1
1
vote
0 answers
How do I run python script with runpy?
I am trying to run a python script and I wanted d to run it with a more pythonic way rather than maybe calling subprocess.run().
I found the runpy library and I am trying to call my script like…

KZiovas
- 3,491
- 3
- 26
- 47
1
vote
1 answer
Combining `runpy` with mocks passes when running alone but fails when running with other tests
When I run the following test alone, it passes. But when I run it with other tests, even if this test is the first to run it fails:
from runpy import run_path
from unittest.mock import patch, MagicMock
@patch('boto3.client', autospec=True)
def…

Ran Halprin
- 471
- 5
- 15
1
vote
0 answers
Is runpy safe to use?
I am writing some code that will require data from downstream the package hierarchy. Consider the following project structure:
├── app/
│ ├── main.py
│ ├── lib.py
│ └── subpck/
│ └── module.py
And the following code:
#…

Algebra8
- 1,115
- 1
- 10
- 23