求免费的那种网站有哪些/长尾关键词爱站
Linux下执行Python脚本 亲测可用
1.Linux Python环境
Linux系统一般集成Python,如果没有安装,可以手动安装,联网状态下可直接安装。Fedora下使用yum install,Ubuntu下使用apt-get install,前提都是root权限。安装完毕,可将Python加入环境变量,这样在使用Python时无须每次都指定安装路径。加入环境变量有两种方法:
方法1:直接在命令终端输入命令,立即生效,但重启后失效,如下。
export PATH="$PATH:/usr/bin/python"
此处只介绍方法1,亲测有效。
2.在服务器上查看python环境是否就绪
输入python -v
[root@iZm5e5bb879Z home]# python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib64/python2.7/site.pyc matches /usr/lib64/python2.7/site.py
import site # precompiled from /usr/lib64/python2.7/site.pyc
# /usr/lib64/python2.7/os.pyc matches /usr/lib64/python2.7/os.py
import os # precompiled from /usr/lib64/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib64/python2.7/posixpath.pyc matches /usr/lib64/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib64/python2.7/posixpath.pyc
# /usr/lib64/python2.7/stat.pyc matches /usr/lib64/python2.7/stat.py
import stat # precompiled from /usr/lib64/python2.7/stat.pyc
# /usr/lib64/python2.7/genericpath.pyc matches /usr/lib64/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib64/python2.7/genericpath.pyc
# /usr/lib64/python2.7/warnings.pyc matches /usr/lib64/python2.7/warnings.py
import warnings # precompiled from /usr/lib64/python2.7/warnings.pyc
# /usr/lib64/python2.7/linecache.pyc matches /usr/lib64/python2.7/linecache.py
import linecache # precompiled from /usr/lib64/python2.7/linecache.pyc
# /usr/lib64/python2.7/types.pyc matches /usr/lib64/python2.7/types.py
import types # precompiled from /usr/lib64/python2.7/types.pyc
# /usr/lib64/python2.7/UserDict.pyc matches /usr/lib64/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib64/python2.7/UserDict.pyc
# /usr/lib64/python2.7/_abcoll.pyc matches /usr/lib64/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib64/python2.7/_abcoll.pyc
# /usr/lib64/python2.7/abc.pyc matches /usr/lib64/python2.7/abc.py
import abc # precompiled from /usr/lib64/python2.7/abc.pyc
# /usr/lib64/python2.7/_weakrefset.pyc matches /usr/lib64/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib64/python2.7/_weakrefset.pyc
3.新建test.py文件,里面简单写一句python语句
#!/usr/bin/python
print “Hello codertalk!”
第一行需增加 #!/usr/bin/python制定为python编译解析
4.修改text.py的权限
chmod u+x test.py
chmod u+x test.py
5.执行文件 python test.py
[root@iZm5e9wyhcZ home]# python test.py
Hello codertalk!
[root@iZm5e9wyb879Z home]# python test.py
Hello codertalk!
[root@iZm5e9wyhc5bb879Z home]# python test.py
Hello codertalk!
[root@iZm5e9wyh79Z home]# python test.py
Hello codertalk!
[root@iZm5e9wy879Z home]# python test.py
Hello codertalk!
参考资料:
https://blog.csdn.net/qq_20553613/article/details/78811011