Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sudopython错误版本_Python_Macos_Version_Sudo - Fatal编程技术网

sudopython错误版本

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

我在运行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 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