How to run a Python script on Windows or Linux
Run a saved .py file in PowerShell or Bash. Find out whether a failed run came from the Python command, the script path, or an input file.
5 min readChoose an editor, manage packages, work with APIs, and make everyday automation reliable.
Run a saved .py file in PowerShell or Bash. Find out whether a failed run came from the Python command, the script path, or an input file.
5 min readCompare IDLE, VS Code, and PyCharm on the same small exercise. See which makes it easiest to find the running interpreter and debug a script.
6 min readChoose a workspace interpreter, verify it with sys.executable, and fix import errors caused by a terminal or debugger using a different Python.
5 min readPause before a Python line in VS Code, inspect local variables, step through the code, and fix breakpoints that never get hit.
5 min readSee what Ruff and Black-style formatting changes, how to check a file before writing it, and how formatting differs from linting and tests.
4 min readFind Python lint messages in the Problems panel, reproduce them with ruff check, and decide when to fix or narrowly suppress a rule.
5 min readInstall Requests with python -m pip, verify the package location, and diagnose ModuleNotFoundError when pip and your editor use different interpreters.
4 min readSee what Python imports, what pip installs, and why an import name can differ from the name of the distribution you installed.
4 min readBuild a wheel from pyproject.toml, inspect its files, and install it in a fresh environment to verify what users will receive.
5 min readCompare src and flat Python package layouts. Check where your tests import code from and catch files missing from a built wheel.
4 min readRun a local command from Python, capture stdout and stderr, and tell an exit error apart from a timeout or an executable that never started.
4 min readChoose Popen when you need to manage a running process. Use communicate() to drain pipes and clean up the child if it times out.
4 min readSend a GET request with params and timeout. Check the HTTP status and returned data before treating an empty result as a successful read.
4 min readUse json= for JSON and data= for form fields. Check the API reply and avoid creating duplicate records after a request times out.
4 min readRead status_code and headers, choose text or bytes, and handle JSON errors and empty HTTP responses before passing data to your application.
4 min readUse requests.Session() for related calls to one service. Know which cookies and headers persist, when connections can be reused, and how to close the session.
4 min readFollow a REST API's next link or cursor, detect repeated pages, and label a partial collection instead of reporting it as complete.
4 min readDesign a Python script that previews proposed changes, detects destination conflicts, and resumes correctly after a partial failure.
4 min readConfigure the Python executable, script arguments, working directory, and run account. Test the job and decide what happens when runs overlap.
4 min readRun a Python module by name, learn how __main__.py works, and see why python -m pip uses the pip belonging to that interpreter.
4 min readConfigure pytest with your project interpreter and use --collect-only to tell missing tests, import errors, and failed assertions apart.
4 min readUse tmp_path in a real pytest example that checks whether a Python function preserves an existing file. Run it on the command line or in VS Code.
4 min read