[英]python - Change python to /usr/local/bin/python?
I'm trying to install opencv
using python2.7
.我正在尝试使用python2.7
安装opencv
。
When I use brew install python
.当我使用brew install python
。 I got我得到了
Warning: python-2.7.11 already installed, it's just not linked警告:python-2.7.11 已经安装,只是没有链接
And then I run brew link python
and brew install python
again got然后我再次运行brew link python
和brew install python
1 export PATH="/usr/local/mysql/bin:$PATH" 1 导出 PATH="/usr/local/mysql/bin:$PATH"
Warning: python-2.7.11 already installed警告:python-2.7.11 已经安装
But which python
still told me I'm using /usr/bin/python
.但是which python
仍然告诉我我正在使用/usr/bin/python
。
I changed my ~/.bash_profile
to我将~/.bash_profile
更改为
1 export PATH="/usr/local/mysql/bin:$PATH"
2 #Setting PATH for Python 3.5
3 # The orginal version is saved in .bash_profile.pysave
4 PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
5 export PATH
6 # Homebrew
7 export PATH="/usr/local/bin:$PATH"
No thing happens.没有任何事情发生。 It seems that I should be using /usr/local/bin/python
because opencv
is installed by homebrew
.似乎我应该使用/usr/local/bin/python
因为opencv
是由homebrew
安装的。
How to solve this?如何解决这个问题?
Did you try closing your terminal session and then open a new one?您是否尝试关闭终端会话然后打开一个新会话? ~/.bash_profile
is only picked up when bash is executed as a login shell, which is the default for Terminal.app when you open a new terminal window. ~/.bash_profile
仅在 bash 作为登录 shell 执行时才会被选取,这是打开新终端窗口时 Terminal.app 的默认设置。 Or you can do source ~/.bash_profile
if you do not want to close the terminal session for some reason.或者,如果您出于某种原因不想关闭终端会话,则可以执行source ~/.bash_profile
。
Side note: You might want to add the following at the top of your ~/.bash_profile
:旁注:您可能希望在~/.bash_profile
顶部添加以下内容:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
So that your ~/.bashrc
is also executed.这样你的~/.bashrc
也会被执行。 Optionally you can also add: (可选)您还可以添加:
if [ -f `brew --prefix`/etc/bash_completion ]; then
source `brew --prefix`/etc/bash_completion
fi
To enable bash completion for brew commands.为 brew 命令启用 bash 完成。
Recent versions of Homebrew and OSX have switched from putting python in /usr/local/bin
to /usr/local/opt/python/libexec/bin
Homebrew 和 OSX 的最新版本已经从将 python 放在/usr/local/bin
切换到/usr/local/opt/python/libexec/bin
You want to do something like:你想做这样的事情:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
To get the homebrew python.获取自制的python。
I changed it to /usr/local/bin
like following:我将其更改为/usr/local/bin
如下:
export PATH="/usr/local/python/libexec/bin:$PATH"
Works perfectly for me.非常适合我。 That's what I want to use.这就是我想要使用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.