[英]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.