如何在PATH环境变量的顶部插入自制程序目录?

2024-04-23 10:48:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我不需要什么帮助。作为您的信息,我是Python的新手,正在尝试修补它。所以,我有一个网站“python的搭便车指南”。现在,我正在进行在MacOSX上安装Python3的一节。这是链接->;http://docs.python-guide.org/en/latest/starting/install3/osx/#pip

不管怎样,我想把它做好,所以我刚格式化了我的Mac电脑,还有Xcode。我按照指令进行操作,上面写着“xcode-select--install”。之后,我开始在终端$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"内安装自制程序

我想我一直都在应付这件事,但问题出在这里。 他说

Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file

所以,通过一些搜索,我用nano编辑了我的路径。通过跟随

 sudo nano /etc/paths

/usr/local/bin
/usr/local/sbin   <<<--When I opened the paths, there wasn't this 'usr/local/sbin' So I typed it.
/usr/bin
/bin
/usr/sbin/
/sbin

当我打开路径时,没有'/usr/local/sbin'。所以我打了出来。 我离开了终点站,回响了那条路,什么也没发生。 如果我做了which python,它显示我/usr/bin/python。 我确实安装了python3,但是当我安装了python -V时,它仍然 Python 2.7.10

如何在PATH环境变量的顶部插入自制程序目录?在

顺便说一句,我怎么能把我的mac电脑设置成python3的默认值呢???在

提前感谢!在


Tags: installofthepath程序yourbinnano
3条回答

/etc/中的文件只在启动时运行,对所有用户都是全局的。我建议您使用主目录中的文件(.bash_profile或.zshrc,具体取决于shell)。每次打开终端时都会读取这些文件。在

添加此行:

export PATH=/usr/local/sbin:$PATH

要更新现有终端,可以通过以下方式更新设置:

^{pr2}$

进入终端并运行:

$ which brew
/usr/local/bin/brew

您将获得brew路径,并确保将此路径添加到~/。profile路径如下:

^{pr2}$

然后运行此命令使更改生效:

$ source ~/.profile

你误解了有关路径的说明。PATH是一个环境变量,可以在您的主目录下的.profile文件中设置(如果不存在,请创建它),您需要将页面所述的内容精确复制到文件底部:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

完成后,重新启动终端,您应该能够使用python3命令。在

相关问题 更多 >