Loanb222 Loanb222 - 4 months ago 9
Python Question

Error Installing OpenCV with Python on OS X

I have been trying to install Open CV 3 on my mac using this tutorial but I cannot get past step three.

So after I do

brew install python


I do

nano ~/.bash_profile


And the at the bottom of the script I paste

# Homebrew
export PATH=/usr/local/bin:$PATH


After that I reload the file like this

source ~/.bash_profile


Finally I check the python like this

which python


And it prints

/usr/bin/python


instead of

/usr/local/bin/python


I have also tried edited the file in TextEdit but it has the same result.

Am I doing something wrong or is this just a bad tutorial?

Thank You in Advance!

Edit:

# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

##
# Your previous /Users/UserName/.bash_profile file was backed up as /Users/UserName/.bash_profile.macports-saved_2016-07-26_at_12:50:19
##

# MacPorts Installer addition on 2016-07-26_at_12:50:19: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.
# Homebrew
export PATH=/usr/local/bin:$PATH


pydoc3.5
python3
python3-32
python3-config
python3.5
python3.5-32
python3.5-config
python3.5m
python3.5m-config

Answer

Is there a

/usr/local/Cellar/python/2.7.12/

directory? (Version number might differ.)

Is there a

/usr/local/bin/python

file?

If the Cellar directory is present, but the file isn't, then Homebrew decided to be careful and not put Python in /usr/local/bin/ immediately.
You could manually do

brew link python

and see if there's now a

/usr/local/bin/python

file.


In your case, it appears you have some files related to Python (they might be from a Python 3 installation, can't tell), such as 2to3. You can safely overwrite them, since Python 2 also has this. Thus:

brew link --overwrite python

is fine.

Note:

Specific Python versions will always exist as python2.7, python3.5 etc (including the full path as necessary). Thus, even overwriting the python executable is safe (provided it's not the system one in /usr/bin): you should then simply be explicit which python executable to use.

Also, when using a tool like pip, you can make sure you're using the correct version by running it e.g. as

/usr/local/bin/pythnon2.7 -m pip <...>

or whatever python executable you want to install things for.

Comments