[英]python2.7 on centos for non root user
I installed Python2.7.6 on Centos 6.5 using make altinstall. 我使用make altinstall在Centos 6.5上安装了Python2.7.6。 If I do python2.7 -V
using root, I get the correct answer. 如果我使用root做python2.7 -V
,我会得到正确的答案。
When I use another user that has sudoers permissions I also see everything as normal. 当我使用另一个具有sudoers权限的用户时,我也会看到一切正常。
When I switch to another user that does not have sudoers then I get bash: python2.7: command not found
. 当我切换到另一个没有sudoers的用户时,我得到了bash: python2.7: command not found
。 When I switch back to root or to my other user (after using the non sudoer user), then suddenly I cannot find Python2.7 there either. 当我切换回root或其他用户(使用非sudoer用户后)时,突然之间我也找不到Python2.7。
How do I get the python to work? 我如何使python工作?
Updated from comments: 从评论更新:
Please add path python2.7
to path variable $PATH
, in the user's ~/.bashrc or ~/.profile
or 请在用户的~/.bashrc or ~/.profile
中将路径python2.7
添加到路径变量$PATH
中
for all users add it to /etc/profile
对于所有用户,将其添加到/etc/profile
You can do so by finding line like export PATH=$PATH:/path/to/binary1:/path/to/binary2
just add absolute path to python2.7
after placing a : at the end of this line. 您可以通过找到以下行来做到这一点,例如export PATH=$PATH:/path/to/binary1:/path/to/binary2
只需在此行的末尾添加:之后,将绝对路径添加到python2.7
。 and source the file on the terminal you are using python2.7
. 并在使用python2.7
的终端上获取文件。
For subsequent logins it will work, but If you have added in /etc/profile file then you shall have to either source it every time or restart the machine once after making changes to file. 对于随后的登录,它将起作用,但是,如果您已添加/ etc / profile文件,则您必须每次都为其提供源,或者在对文件进行更改后必须重新启动计算机。
The answer to other part of the question depends on how you are moving back to root
. 问题的其他部分的答案取决于您如何重新root
。
move back to root
via 通过移动回到root
sudo su -
or if you do not need sudo
then 或者如果您不需要sudo
su -
This is a simple PATH
issue. 这是一个简单的PATH
问题。
Modify /etc/profile
and add something like: 修改/etc/profile
并添加如下内容:
export PATH="/path/to/python:$PATH"
Normally on many CentOS systems I maintain I install a custom Python to /usr/local/` so my
PATH`` modification becomes: 通常,在许多CentOS系统上,我都会在/usr/local/` so my
安装一个自定义Python, /usr/local/` so my
PATH``修改为:
export PATH="/usr/local/bin:$PATH"
Note: This should work in all cases as long as you get the PATH
right regardless of which user you are logged in with or the use of sudo. 注意:只要您正确使用PATH
无论您使用哪个用户登录或使用sudo,此方法在所有情况下都应起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.