如何在linux中从不同的路径运行python程序

时间:2016-12-01 09:34:43

标签: python linux

我为root用户安装了2个python,为普通用户安装了一个python。 我想为普通用户使用python安装为root用户运行python程序。怎么办呢?

python -c "import sys; print '\n'.join(sys.path)"

/home/ubuntu/anaconda2/lib/python27.zip
/home/ubuntu/anaconda2/lib/python2.7
/home/ubuntu/anaconda2/lib/python2.7/plat-linux2
/home/ubuntu/anaconda2/lib/python2.7/lib-tk
/home/ubuntu/anaconda2/lib/python2.7/lib-old
/home/ubuntu/anaconda2/lib/python2.7/lib-dynload
/home/ubuntu/anaconda2/lib/python2.7/site-packages
/home/ubuntu/anaconda2/lib/python2.7/site-packages/Sphinx-1.3.5-py2.7.egg
/home/ubuntu/anaconda2/lib/python2.7/site-packages/cryptography-1.0.2-py2.7-linux-x86_64.egg
/home/ubuntu/anaconda2/lib/python2.7/site-packages/setuptools-19.6.2-py2.7.egg

这是针对root用户的

sudo python -c "import sys; print '\n'.join(sys.path)"

/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/rlp-0.4.6-py2.7.egg
/usr/local/lib/python2.7/dist-packages/devp2p-0.8.0-py2.7.egg
/usr/local/lib/python2.7/dist-packages/ethereum-1.6.0-py2.7.egg
/usr/local/lib/python2.7/dist-packages/ethereum_serpent-2.0.2-py2.7-linux-x86_64.egg
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/python2.7/dist-packages/ubuntu-sso-client

我想使用anaconda python安装运行python程序。但我不想改变路径,因为有其他用户使用root python安装。总之,我想以root用户身份运行此程序,但不更改root用户的默认python安装路径。

1 个答案:

答案 0 :(得分:1)

只需指定要运行的python安装的完整路径。

sudo /home/ubuntu/anaconda2/bin/python -c "import sys; print '\n'.join(sys.path)"