[英]sudo python wrong version
运行 sudo 时我得到了 python 2.7。 我尝试从我的原始用户和 root 更改我的 .bash_profile 和 .bashrc,但无济于事。
$ python
Python 3.5.2 (default, Oct 11 2016, 05:05:28)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ sudo python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
我在两个用户的两个 bash 配置中都使用了alias python='python3'
并提供了它们。
如何让 python 3.5 加载sudo python
?
编辑:这是在 OSX EDIT2 上:我也试过查看which
python。
$ which python
/usr/bin/python
$ sudo which python
/usr/bin/python
两个不同的 python 必须在您计算机上的不同位置运行。 从终端,尝试运行
whereis python
和sudo whereis python
。 whereis 会告诉你你运行 python 的路径。 然后,一旦你弄清楚 3.5 在哪里,你就可以运行sudo <path to 3.5>
作为一种可能的解决方法,您可以添加到 bash_aliases (或类似的):
alias python='/usr/bin/python3'
alias sudo='sudo '
进而:
. .bashrc
为root用户找到python的位置。 在 shell 中键入sudo -i
以更改为 root 用户。 然后输入which python
。
不建议更改系统的python 版本。 一些系统脚本可能会因此面临问题。 您可以在 root 用户bashrc
或类似文件中设置别名,这些文件应该位于/etc
(例如/etc/bashrc
)目录中。
我不在 mac 中,也没有尝试过。 所以答案没有经过测试。
sudo
不提供您的(或 root 的) .bashrc
,并覆盖调用用户的大部分环境,因此添加别名没有帮助。
为什么不直接输入sudo python3
?
根据您的安全设置, sudo -E python
也可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.