如何将 anaconda 添加到 PATH?

2022-01-10 00:00:00 python path spyder version anaconda

问题描述

我在我的系统 (Mac OS) 上下载了 Anaconda,目前只是为了使用 Spyder 在 Python 中编写代码.我有两个问题,对于比我更适合计算机的人来说,这可能很容易解决.我很乐意提供帮助!

I downloaded Anaconda on my system (Mac OS), for now solely for the purpose of using Spyder to code in Python. I am having two issues, which are probably easy to solve for someone who is more fit with computers than me. I would be glad for help!

  1. 是否将 anaconda 添加到 PATH,如果是,如何添加?

在 此线程中,我得到了更新方面的帮助Anaconda 和 Spyder,因为执行 conda update anacondaconda update spyder 行会导致 zsh: command not found.显然,这与 anaconda 未添加到我的路径有关.在那个线程中,我得到了一种解决方法,而无需将 anaconda 添加到我的路径中.但是,每次更新之前我都必须运行命令行.

In this thread here I got help with updating Anaconda and Spyder, since executing the lines conda update anaconda and conda update spyder would result in zsh: command not found. Apparently this has to do with anaconda not being added to my PATH. In that thread I was offered a workaround without adding anaconda to my path. However I would have to run a commandline everytime before I update it.

现在,我完全承认,我什至不知道将 anaconda 添加到我的路径中意味着什么.而且我不知道添加它有什么利弊.但是我有点想添加它,这样我每次更新时都不必查找和运行这个命令行.有人可以解释一下我是否应该将 anaconda 添加到 PATH 中,如果是的话,如何?

Now, I fully admit, that I don't even know what it means to add anaconda to my path. And I don't know what are the pros and cons of adding it, or not. But I kind of would like to add it, such that I don't have to look up and run this command line every time when I update. Could someone please explain if I should add anaconda to PATH, and if so, how?

  1. 哪个 Python 发行版被什么人使用?

我对系统上的 python 发行版感到非常困惑.

I am getting very confused with python distributions on my system.

  • 在我看到的 Spyder 底部的面板中,它使用 Python 3.7.4..
  • 在 Spyder 的 IPython 控制台中,我看到它使用 Python 3.7.0.
  • 如果我在终端中运行 python --version 我会得到 Python 2.7.16
  • 如果我在终端中运行 python3 --version 我会得到 Python 3.7.3
  • In the panel at the bottom of Spyder I see, that it uses Python 3.7.4..
  • In the IPython console of Spyder I see that it uses Python 3.7.0.
  • If I run python --version in a terminal I get Python 2.7.16
  • If I run python3 --version in a terminal I get Python 3.7.3

为什么我的系统上有所有这些不同的版本?如果我在 Spyder 中开发了一个脚本,然后想从终端运行它,那么我当然想使用与 Spyder 使用的相同的 python 解释器来运行它.我怎样才能确保是这种情况?例如,我是通过 python script.py、`python3 script.py´ 还是通过另一个命令行运行名为 script.py 的脚本?

Why are all these different versions on my system? If I develop a script in Spyder, and then want to run it from the terminal, then I of course would like to run it with the same python interpreter as the one Spyder uses. How can I make sure this is the case? Do I for example run a script named script.py by python script.py, by `python3 script.py´, or by yet another command line?

我什至不确定 pythonpython3 是否调用 anaconda 附带的发行版,因为当我运行 which pythonwhich python3 我得到 /usr/bin/python 或用户 /usr/bin/python3,而 anaconda 安装在 Users/opt/<my_username>/anaconda3/bin.

I am not even sure if python or python3 calls the distributions which came with anaconda, since when I run which python or which python3 I get /usr/bin/python or user /usr/bin/python3, while anaconda is installed in Users/opt/<my_username>/anaconda3/bin.

所以,如果有人也可以为我清除这里的迷雾,那就太好了!:)

So if someone could clear the fog here for me please as well, that would be great! : )

感谢您的帮助!


解决方案

macOS 自带一个 Python v(大多数时候是 2.x),你已经为另一个版本安装了 anaconda.要检查这一点,您可以先运行以下命令:

A Python v (most of the time 2.x) comes with macOS and you have installed anaconda for the other one version. to check this you can first run this command:

conda env list

如果您已将 python2x 作为新环境安装,它将显示为:

if you have installed python2x as a new env it will show up as:

# conda environments:
#
base                  *  /Users/your_user/Applications/anaconda3
py2                      /Users/your_user/Applications/anaconda3/envs/py2

如果你只看到'base'(对我来说是 anaconda3 所以 python 3.x),那么它说你的 macOS 有 python2.x(或相反).通常以下命令会显示您的默认 python 版本:

if you only see 'base' (which is for me is anaconda3 so python 3.x) then it says that you had python2.x with your macOS ( or the reverse). Normally the below command shows your default python version:

    python --version
output (for me): Python 3.7.6

其中显示了您的 Anaconda 版本.如果你想使用另一个,你可以1)在这里使用我的答案来改变它:如何将默认的python3设置为python3.7?

Which shows the version you have with your Anaconda. If you want to use the other one, you can either 1) change this by using my answer here: How to set the default python3 to python3.7?

2) 或者您可以在您的 anaconda 环境中添加一个新的env"(如果在上面您只看到base").此处提到了说明:https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

2) or you can add a new "env" to your anaconda environments (if in the above you see only 'base'). The instructions are mentioned here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

相关文章