Execute python program from command line without script file
i found a solution, maybe it will help, you can use EOF
$ python << EOF
> def test2():
> print("test2")
>
> def test_func():
> test2()
> print("test_func")
>
> test_func()
> EOF
# output
test2
test_func
You can also use python -c
with """
$ python -c """
def test2():
print("test2")
def test_func():
test2()
print("test_func")
test_func()
"""
run a python script in terminal without the python command
You use a shebang line at the start of your script:
#!/usr/bin/env python
make the file executable:
chmod +x arbitraryname
and put it in a directory on your PATH (can be a symlink):
cd ~/bin/
ln -s ~/some/path/to/myscript/arbitraryname
Run Python script without activating virtual environment
Use chmod +x script.py
to make your script executable. The #!shebang
selects an interpreter.
You can call an executable from the shell like so:
/path/to/script.py
Or:
cd /path/to; ./script.py
Alternatively, you can put your script in one of the directories defined by $PATH
, which will let you call it just like any other utility.
Related Topics
Groupby Pandas Dataframe and Select Most Common Value
Get Local Network Interface Addresses Using Only Proc
Pip Is Not Working for Python 3.10 on Ubuntu
Anaconda: Disable Prompt Change
Correct Daemon Behaviour (From Pep 3143) Explained
How Would a Python Script Running on Linux Call a Routine in a Python Script Running Under Wine
Python Parsing Log File to Extract Events in Real Time
How to Make Shell Output Redirect (>) Write While Script Is Still Running
Why File Read Is Faster on Reading Again
Conversion Text to Number in Python
Python List by Value Not by Reference
Get Mouse Deltas Using Python! (In Linux)
Setting Ld_Library_Path from Inside Python
Why Does Python "Preemptively" Hang When Trying to Calculate a Very Large Number
Running a Python Script Using Cron