(转)Linux下运行python
时间:2022-12-11阅读:68来源:柠檬博客作者:柠檬博客
原文: http://blog.csdn.net/jackywgw/article/details/48847187
在linux命令行下运行python,可以直接输出hello world
[python] jackywgw@jackywgw-A8F:~/python_learning$ python Python 3.3.6 (default, Apr 17 2015, 00:20:01) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print('hello world') hello world >>>如果将print ('hello world')写入first_helloworld.py中,通过python first_helloworld.py可以输出hello world.
如果想直接运行./first_helloworld.py,则先要chmod u+x first_helloworld,然后还要在first_helloworld.py最前面加入#!/usr/bin/python3
[python] #!/usr/bin/python3 print('hello world')#!/usr/bin/python3 这个为python的可执行路径,可以通过which python3/ which python来获取。
[plain] jackywgw@jackywgw-A8F:~/python_learning$ which python3 /usr/bin/python3 jackywgw@jackywgw-A8F:~/python_learning$ which python /usr/bin/python jackywgw@jackywgw-A8F:~/python_learning$这样就可以直接运行./first_helloworld.py输出hello world了。
68人参与,
0条评论
登录后显示评论回复