2

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

Loanb222
  • 841
  • 1
  • 11
  • 29
  • MacPorts and HomeBrew: just be careful that they don't interfere. Also, why install Python with HomeBrew when you also have a Python 3.5 installed in `/Library/`'. Sounds like you have a multitude of Python installation on your system, which at some point will bite each other. –  Aug 03 '16 at 22:28
  • The tutorial said this "t’s bad form to use the system Python as your main interpreter. And this is especially true if you intend on using virtualenv and virtualenvwrapper" – Loanb222 Aug 03 '16 at 22:33
  • If using your system Python is fine, there seems to be no need to install a Homebrew Python. Virtualenvs tend to be overrated, and mostly useful for development purposes: packages (and Python version) can be separated without virtualenvs and without problems when done properly. –  Aug 03 '16 at 22:41
  • Do you know any tutorials that use OpenCV with the system python becuase the only ones that I can find use HomeBrew Python – Loanb222 Aug 03 '16 at 22:43
  • Just follow the instructions as they are and ignore the steps in which they say how to install homebrew's python. That's it. – hecvd Aug 03 '16 at 23:07

2 Answers2

1

Okay so one brute force solution could be this one https://stackoverflow.com/a/9821036/128517

But maybe you could check the value of your $PATH after source ~/.bash_profile typing

> echo $PATH 

and see if /usr/local/bin is indeed at the beginning.

if it's not, you might need to check if there's another export before yours or maybe you need to edit .profile instead.

Community
  • 1
  • 1
hecvd
  • 659
  • 1
  • 8
  • 24
1

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.

  • I got this error while I was linking python. Would I want to ovwrite those files Linking /usr/local/Cellar/python/2.7.12... Error: Could not symlink bin/2to3 Target /usr/local/bin/2to3 already exists. You may want to remove it: rm '/usr/local/bin/2to3' To force the link and overwrite all conflicting files: brew link --overwrite python To list all files that would be deleted: brew link --overwrite --dry-run python – Loanb222 Aug 04 '16 at 13:52
  • The error message is pretty clear: you have existing files, which may be from a previous Python installation. You can safely overwrite them (but feel free to use the `--dry-run` option first). See my updated answer. –  Aug 05 '16 at 00:26