简体   繁体   English

如何让命令行中的 python3 指向我用 homebrew 安装的版本?

[英]How do I get python3 in the command line to point to the version I installed with homebrew?

This is what I see in terminal:这是我在终端中看到的:

My-MacBook-Pro:~ username$ which python3
/usr/bin/python3
My-MacBook-Pro:~ username$ python3
-bash: /usr/local/bin/python3: No such file or directory

There is no python3 binary at /usr/local/bin/ . /usr/local/bin/中没有python3二进制文件。

There is a file called python3 at /usr/bin/ however.但是, /usr/bin/中有一个名为python3的文件。

You may need to put it in the front of your path.您可能需要将其放在路径的前面。 If you are using bash, do this:如果您使用的是 bash,请执行以下操作:

echo 'export PATH="/usr/local/opt/python/libexec/bin:$PATH"' >> ~/.bash_profile

Then either source ~/.bash_profile or open a new terminal.然后 source ~/.bash_profile 或打开一个新终端。 Then try which python and it should show you the version in this directory.然后尝试which python它应该会显示此目录中的版本。 Or type in python --version and it will report "Python 3.7.7".或者输入python --version ,它会报告“Python 3.7.7”。

Which version did you install?你安装的是哪个版本?

Run brew info [python-package] and you should see something like this (for example I installed python@3.8 , so I ran brew info python@3.8 )运行brew info [python-package]你应该看到类似这样的东西(例如我安装了python@3.8 ,所以我运行了brew info python@3.8

If you need to have python@3.8 first in your PATH run:
  echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.zshrc

Just run the line and restart terminal, it should be working.只需运行该行并重新启动终端,它应该可以正常工作。

I closed terminal and then reopened it and it fixed the problem.我关闭终端然后重新打开它并解决了问题。 Now typing python3 opens the python interpreter.现在输入 python3 打开 python 解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 textmate 指向我在命令行获得的相同版本的 python - How to point textmate to the same version of python I get at the command line 如何在homebrew中将python3符号链接更改为“python” - In homebrew how do I change the python3 symlink to only “python” 安装自制软件 - 混淆版本和以前的安装 - 如何在没有警告的情况下安装所有内容? - Installation of homebrew - confusion over version and previous installation - how do I get everything installed without warnings? 如何找到安装python3的路径? - How do I find the path where python3 is installed? 如何获得直线上的曲线点? - How do I get a curve point on a line? 如何在python3中获得glob表达式的反斜杠转义版本 - how do I get backslashed escaped version of a glob expression in python3 如何将Tcl / Tk的ActiveState分发链接到HomeBrew安装的Python - How do I link the ActiveState distribution of Tcl/Tk to HomeBrew installed Python 我在Mac上安装了python 2.7和3.6。 如何找到与Python3相关的pip版本? - I have python 2.7 and 3.6 installed on my mac. How to find the version of pip associated with Python3? 如何让Homebrew安装python3导入图形工具? - How to let python3 import graph-tool installed by Homebrew? Python3 MatPlotLib:如何获取多个线图 - Python3 MatPlotLib : How can I get Multiple Line Plots
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM