gpt4 book ai didi

python - 尽管 ~/.bashrc 和 ~/.bash_aliases 中有导出和别名,但终端中的默认 python 不会改变

转载 作者:太空宇宙 更新时间:2023-11-03 13:59:30 24 4
gpt4 key购买 nike

我已按照 this 等示例中的说明进行操作,和 this .

我的 ~/.bashrc 文件中有这一行

export python="/usr/local/bin/python3.6"

这行在我的 ~/.bash_aliases 文件中

alias python='/usr/local/bin/python3.6'

这是我的路径变量

/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS

我仍然有以下 python 版本和路径

User$ which python
/usr/bin/python
User$ python --version
Python 2.7.10

我也已经尝试退出终端并重新打开

这是目录/usr/local/bin/python3.6* 和/usr/bin/python* 中的内容

User$ /usr/local/bin/python3.6
python3.6 python3.6-config python3.6m-config
python3.6-32 python3.6m
User$ /usr/bin/python
python python2.6-config pythonw
python-config python2.7 pythonw2.6
python2.6 python2.7-config pythonw2.7

谢谢

最佳答案

我认为问题可能是,您启动了一个查找 ~/.bash_profile 的登录 shell,而 ~/.bash_aliases 并非源自 ~/.bash_profile。因此,~/.bash_aliases 中的 alias 命令从未被执行过。您可以通过调用alias python来检查这一点。

顺便说一句,导出一个名为 python 的变量在你的情况下是没有意义的,因为它 永远不会被使用。

关于读取哪些~/.bash*文件,可以引用INVOCATION章节的man bash。这是其中一些。

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

关于python - 尽管 ~/.bashrc 和 ~/.bash_aliases 中有导出和别名,但终端中的默认 python 不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49354578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com