linux 怎样找到python解释器

linux 怎样找到python解释器


牧羊人nacy
浏览 569回答 3
3回答

红糖糍粑

Python是解释型脚本语言,在执行时,逐句解释执行,不需要进行预编译。但需要有自身的Python解释器。所以在执行Python代码时,需要指定python解释器。指定解释器方法:在文件开头添加搜索路径,linux OS中一般安装后的默认路径如下#!/usr/bin/env python 或者#!/usr/locat/bin/python如果没有找到,可以通过命令查询python路径whereis python或者which pythonWindows OS可以通过以下方式查询python路径或者第三方模块安装路径。>>> import sys>>> sys.path['C:\\Users\\zx\\Desktop', 'C:\\Users\\zx\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages']cmd目录下运行python -V可查看python版本修改默认python版本先查看安装的python路径:justin18chan@justin18chan:~$ whereis pythonpython: /usr/bin/python /usr/bin/python3.5 /usr/bin/python2.7-config /usr/bin/python3.5m /usr/bin/python2.7 /usr/lib/python3.5 /usr/lib/python2.7 /etc/python /etc/python3.5 /etc/python2.7 /usr/local/bin/python3.6m-config /usr/local/bin/python3.6-config /usr/local/bin/python3.6m /usr/local/bin/python3.6 /usr/local/lib/python3.5 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.5m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz使用ln -s命令来修改,命令如下:justin18chan@justin18chan:~$ sudo rm /usr/bin/python[sudo] password for justin18chan: justin18chan@justin18chan:~$ sudo ln -s /usr/bin/python3.5 /usr/bin/pythonjustin18chan@justin18chan:~$ pythonPython 3.5.2 (default, Sep 14 2017, 22:51:06)

潇潇雨雨

import syssys.versionsys.path
打开App,查看更多内容
随时随地看视频慕课网APP