Install and import site-packages for Python 2 and 3 on Mac I installed brew and then

brew install python
brew install python3


Install flask with pip

pip install flask


Try

python -c 'import flask'


But I got exception

ImportError: No module named flask


Set and export PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages


So far so good. But when I tried to install a package with pip3 for Python 3, I got error message

Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: ":/usr/local/lib/python2.7/site-packages"
     You should `unset PYTHONPATH` to fix this.


How to use site-packages without the PYTHONPATH trick to make both pip and pip3 usable and both Python 2 and Python 3 able to import site-packages?
You should consider install pyenv for this.


  pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.


To install, just type:

$ brew install pyenv


Add this to your .bash_profile:

echo 'export PYENV_ROOT="$HOME/.pyenv"' &gt;&gt; ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' &gt;&gt; ~/.bash_profile
echo 'eval "$(pyenv init -)"' &gt;&gt; ~/.bash_profile


Once installed use pyenv to install python versions you need:

$ pyenv install -l/--list --&gt; List all available versions
$ pyenv install 2.7.6
$ pyenv install 3.3.3


Run this command after you install a python version:

$ pyenv rehash


You can specify multiple versions via PYENV_VERSION at once. Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,

$ pyenv shell 2.7.6 3.3.3
$ pyenv versions
  system
* 2.7.6 (set by PYENV_VERSION environment variable)
* 3.3.3 (set by PYENV_VERSION environment variable)
$ python --version
Python 2.7.6
$ python2.7 --version
Python 2.7.6
$ python3.3 --version
Python 3.3.3