Python mac 上的 .profile 文件在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49997987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:21:22  来源:igfitidea点击:

Where is the .profile file on mac?

pythonmacoshomebrewmacos-sierra

提问by Andile

I have a MacBook Pro 13` inch (without touch bar) and it is running mac os sierra. I have installed Xcode, command line tools and homebrew. Now I want to install python 3 and make it a default interpreter when calling it from the terminal. I have found this guide http://docs.python-guide.org/en/latest/starting/install3/osx/and I get confused when they say I should add the path to the ~./profile but I don't know where to find the file. Can somebody help with step by step guide on how to create it if it not there?

我有一台 13 英寸的 MacBook Pro(没有触控栏),它运行的是 mac os sierra。我已经安装了 Xcode、命令行工具和自制软件。现在我想安装 python 3 并在从终端调用它时使它成为默认解释器。我找到了这个指南http://docs.python-guide.org/en/latest/starting/install3/osx/当他们说我应该将路径添加到 ~./profile 但我没有知道在哪里可以找到文件。如果没有,有人可以帮助逐步指导如何创建它吗?

Thanks

谢谢

回答by Mansuro

The file you are looking for depends on your shell, so if you are using bash, which is the default shell on Mac systems, it will be either ~/.bash_profile, or ~/.bashrcdepending on whether you are in a login shell or non-login shell respectively.

您要查找的文件取决于您的 shell,因此,如果您使用的bash是 Mac 系统上的默认 shell,则它要么是~/.bash_profile,要么~/.bashrc取决于您分别处于登录 shell 还是非登录 shell。

Mac Terminalruns a login shell every time a new terminal window is open, and it calls .bash_profile, so you should use ~/.bash_profile.

MacTerminal每次打开一个新的终端窗口时都会运行一个登录 shell,它会调用.bash_profile,所以你应该使用~/.bash_profile.

回答by Saurabh Patil

I felt to add something here that ate a lot of my time when I had a similar issue.

我觉得在这里添加一些东西,当我遇到类似问题时,它占用了我很多时间。

Many a times the .profile or the .bash_profile (in case of bash shell) is not present. This is typically when you have freshly installed the OS or when you're on a new machine. This gets confusing as one may think if the installation wasn't correct etc. Nothing to worry about. If you don't find these files then simply create it new using vi or whatever means (GUI) and you're good to go. Having a shell doesn't mean you have these files too and you have to create it yourself if you're the first one to use it.

很多时候 .profile 或 .bash_profile (在 bash shell 的情况下)不存在。这通常是在您全新安装操作系统或在新机器上时。如果安装不正确等等,这会让人感到困惑。没有什么可担心的。如果您没有找到这些文件,那么只需使用 vi 或任何方式(GUI)创建新文件,您就可以开始了。拥有 shell 并不意味着你也拥有这些文件,如果你是第一个使用它的人,你必须自己创建它。