Macos – Python 2.x and Python 3.x with Beautiful Soup Package on Mac OSX 10.9.5

installationlibrariesmacospython

I am fairly new to Python and have run into some problems installing Beautiful Soup. I am running Mac OSX 10.9.5.

I installed and used Python 3.4 during a summer and installed Beautiful Soup 4 for a project. That installation worked fine. I am now needing to use Python 2.7 with Beautiful Soup. Suspecting that I would need to install a different version of Beautiful Soup I went ahead and ran my Python code to be sure. When my code tries to import bs4 I get an error. Call and error:

from bs4 import BeautifulSoup
ImportError: No module named bs4

However, when I try to install Beautiful Soup from the console within PyCharm where I am using Python 2.7 the installation fails:

pip install beautifulsoup4
Requirement already satisfied

I also tried to install from a new terminal window opened from the Python 2.7 folder in hope that the install would be focused there. Same result:

 MacBook-Pro-i7:Python 2.7 InnoVition$ pip install beautifulsoup4
 Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Applications/anaconda/lib/python3.4/site-packages

Is there some way I can temporarily "hide" the bs4 installation associated with Python 3.4 so the installation to Python 2.7 can proceed? Any other recommendations?

Best Answer

If you know where the Python 2.7 site-packages is, you could set a variable like:

export PYTHONPATH=/my-path-to/python2.7/site-packages:$PYTHONPATH

Perhaps you also could try virtualenv package in order to have different Python versions working really easy.

Related Question