I installed python3 using brew, all the modules installed thru pip are located at /usr/local/lib/python3.7/site-packages

How do I let the macOS preinstalled python 2.7 access those modules (b/c I know the module I want to import work for pyhton2.7 too) ?

If I just set PYTHONPATH=/usr/local/lib/python3.7/site-packages, I got this error message:

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

I know I can install an individual module by running sudo python -m pip install module xxx (using sudo to install it in /Library/Python/2.7/site-packages)

But is there any easy way to just let pyhton access my python3 modules? If someone has experienced this before and tell me there is none I will also appreciate!

  • would you be able to import them like one imports self-written modules ? You can write a script or a note(which has all the necessary paths pre-written) to keep it handy.
    – anki
    Commented Dec 25, 2019 at 17:40

1 Answer 1


Given the differences in the codebase, not every library will work for both python3 and python2, unless they've gone to the trouble of ensuring compatibility.

You should just be able to run pip install name from the command line to install correctly on the system python.

  • say for example, redis module pypi.org/project/redis, it says work for python2 & 3, do you mean its python 2 version is different from python 3 and can't be used interchangeable ? I am really doubt it. Commented Dec 25, 2019 at 8:29
  • @Qiulang OK: they've gone to the trouble of ensuring that it will work on 2 and 3. But that's not always going to be true.
    – benwiggy
    Commented Dec 25, 2019 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .