sudopython错误版本
我在运行sudo时得到了python2.7。我尝试从原始用户和root更改.bash_配置文件和.bashrc,但没有效果sudopython错误版本,python,macos,version,sudo,Python,Macos,Version,Sudo,我在运行sudo时得到了python2.7。我尝试从原始用户和root更改.bash_配置文件和.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 informa
$ 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'
,并将它们源代码化
如何使用sudopython
加载python 3.5
编辑:这是在OSX上
EDIT2:我还试着研究了哪一种python
$ which python
/usr/bin/python
$ sudo which python
/usr/bin/python
这两种不同的蟒蛇必须从计算机上的不同位置运行。从终端,尝试运行
whereis python
和sudo whereis python
。whereis将告诉您运行python的路径。然后,一旦您确定了3.5的位置,就可以运行sudo
作为一种可能的解决方法,您可以将其添加到bash_别名(或类似别名)中:
然后:
. .bashrc
查找根用户的python位置。在shell类型sudo-i
中更改为root用户。然后键入哪个python
不建议更改系统的python版本。一些系统脚本可能会因此而面临问题。您可以在根用户bashrc
或类似文件中设置别名,这些文件应位于/etc
(例如/etc/bashrc
)目录中
我不在mac电脑里,也没试过这个。因此答案没有经过测试。sudo
不会为您(或root用户)的.bashrc
提供源代码,并覆盖调用用户的大部分环境,因此在那里添加别名没有帮助
为什么不直接键入sudo python3
根据您的安全设置,sudo-epython
也可以工作。尝试运行env | grep PATH和sudo env | grep PATH查看输出
. .bashrc