Calling Python from bash: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 5: Line 5:
=Overview=
=Overview=
This article summarizes a series of aspects related to invoking Python program from bash.
This article summarizes a series of aspects related to invoking Python program from bash.
=Inline Python Code=
Use bash  [[Bash_Input/Output#Here-Docs|here-doc]]:
<syntaxhighlight lang='bash'>
  python3 <<EOF
print('blah')
EOF
</syntaxhighlight>
Also see: {{Internal|Python_Language_Modularization#Python_Script|Python Script}}


=Using the Interpreter from the a Virtual Environment=
=Using the Interpreter from the a Virtual Environment=

Revision as of 16:57, 2 May 2023

Internal

Overview

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

Using the Interpreter from the a Virtual Environment

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 ...

Running a Python Program with a Bash Wrapper

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

Bash to Python Function Mapping

Bash to Python Function Mapping