Calling Python from bash: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 12: Line 12:
<font color=darkkhaki>TODO: reconcile with [[Python Project Layout]]</font>.
<font color=darkkhaki>TODO: reconcile with [[Python Project Layout]]</font>.


==Python Code and Tests Maintained within the Project Structure==
==Python Source Code and Tests Maintained within the Project Structure==
 
==Only Externally Published Packages==
==Only Externally Published Packages==
==Using the Interpreter from the a Virtual Environment==
==Using the Interpreter from the a Virtual Environment==

Revision as of 17:11, 2 May 2023

Internal

Overview

This article summarizes a series of aspects related to invoking Python program from bash.

Running a Python Program with a Bash Wrapper

Check out these links for the meaning of standalone Python program and Python script.

TODO: reconcile with Python Project Layout.

Python Source Code and Tests Maintained within the Project Structure

Only Externally Published Packages

Using the Interpreter from the a Virtual Environment

TODO

If you want to use the interpreter from a specific virtual environment instead of the interpreter found in PATH, explicitly use the path to the binary from the virtual environment directory:

$(dirname $0)/venv/bin/python ...

Inline Python Code

Use bash here-doc:

  python3 <<EOF
print('blah')
EOF

Also see:

Python Script

Bash to Python Function Mapping

Bash to Python Function Mapping