我刚从Windows环境迁移过来。我已经在一个单独的目录中安装了Python 3.2。在Ubuntu shell中,我如何获取Python的安装路径?
有没有办法让shell在运行时知道/选择要用于进一步代码执行的Python版本?
在Ubuntu Linux中是否也有环境变量和搜索路径之类的东西?
有没有办法让shell在运行时知道/选择要用于进一步代码执行的Python版本?
在Ubuntu Linux中是否也有环境变量和搜索路径之类的东西?
第一个问题:
which python
虽然通常是 /usr/bin/python
对于2.7版本。
第二个问题:
从终端和python2.7运行:python2.7 yourfile.py
。
类似地,对于3.2版本:python3.2 yourfile.py
,尽管3.2版本不是默认安装的。(你可以使用apt-get install python3.2
进行安装。)
python yourfile.py
的行为取决于你的Python解释器使用的是哪个替代方案。你可以通过以root
身份发出update-alternatives python
命令(或者使用su
)来更改它。
第三个问题:
环境变量是与shell相关的,但你可以使用echo $variable
将其输出,并使用variable=value
(来自bash
)来设置它们。搜索路径简单地称为PATH
,你可以通过输入echo $PATH
来获取你的搜索路径。
希望这对你有所帮助。
whereis <program>
。whereis python2.7
whereis python3.2
dpkg -S python2.7
dpkg -S python3.2
dpkg -S python2.7 >log.txt
gedit log.txt
使用Python 3.2运行.py文件
python3.2 <file.py>
type -a python
或者
type -a python3
type
命令以及它的作用,特别是使用-a
参数的一些详细说明会很有帮助。 - Danny Bulliswhereis python2.7
针对 Python3.2
whereis python3.2
which python3
或者
whereis python3
>>> import sys
>>> sys.path
which python2.7
和which python3.2
将返回每个解释器的安装路径(如果未安装,则不返回任何内容)。 - Wolfer