PG1X WIKI

My Knowledge Base

User Tools

Site Tools


tech:se:python:hello-python:hello-python

Hello Python

on Ubuntu 17.10

✘╹◡╹✘  18-03-19 22:46:50 /home/wnoguchi
% python -V
zsh: command not found: python
✘╹◡╹✘  18-03-19 22:46:55 /home/wnoguchi
% python -v
zsh: command not found: python
✘╹◡╹✘  18-03-19 22:47:07 /home/wnoguchi
% which python3
/usr/bin/python3
✘╹◡╹✘  18-03-19 22:47:14 /home/wnoguchi
% python3 -V
Python 3.6.3

Python2.7 not found anymore.

✘╹◡╹✘  18-03-19 22:47:24 /home/wnoguchi
% python3
Python 3.6.3 (default, Oct  3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello world')
hello world

to quit, type Ctrl+D.

>>>  <- Enter Ctrl+D
✘╹◡╹✘  18-03-19 22:48:11 /home/wnoguchi
% python3
Python 3.6.3 (default, Oct  3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
hello.py
#!/usr/bin/env python
 
print ('hello world from script.')
✘╹◡╹✘  18-03-19 22:48:18 /home/wnoguchi
% vim hello.py
✘╹◡╹✘  18-03-19 22:59:35 /home/wnoguchi
% chmod +x hello.py
✘╹◡╹✘  18-03-19 22:59:40 /home/wnoguchi
% ./hello.py
/usr/bin/env: ‘python’: No such file or directory

fix shebang.

hello.py
#!/usr/bin/env python3
 
print ('hello world from script.')
✘╹◡╹✘  18-03-19 22:59:43 /home/wnoguchi
% vim hello.py
✘╹◡╹✘  18-03-19 22:59:58 /home/wnoguchi
% ./hello.py
hello world from script.
tech/se/python/hello-python/hello-python.txt · Last modified: 2018/03/19 23:07 by wnoguchi