0

When I run python -V from terminal, I see that Python 2.7.10 is installed. I want to keep this as the "global" version as OSX utilizes it.

When I run Idle, I see that Python 3.6.0 is running. How do I install libraries to this version of Python?

For example, if I run pip install bs4, the library is installed here beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.5.3-py2.7.egg - which is obviously Python 2.7.

So when I run my script from Idle, I get the following error:

ModuleNotFoundError: No module named 'bs4'
JeremyE
  • 1,368
  • 4
  • 20
  • 40
  • 1
    `pip3 install bs4 ` for [pip3](http://stackoverflow.com/questions/20082935/how-to-install-pip-for-python3-on-mac-os-x) – Smart Manoj Jan 24 '17 at 00:49

3 Answers3

3

You want to use virtualenv. It sounds like you have two versions of Python installed and you need to focus on one while being able to manage the packages in each. Virtualenv will do this for you.

First install virtualenv (https://virtualenv.pypa.io/en/stable/), Second run it specifying the version of python you want as so: `virtualenv -p /usr/bin/python2.6 Third you can use pip to install packages directly into this environment. This increases the amount of disk space you need, but will allow you greater control over your code.

1

When you have two versions of python, you will need to specify which version of python you would like to run. You can do this with the activate command. For example:

activate python3

Once you have activated the python 3 environment, you can then run pip:

pip3 install bs4

which will install the beautiful soup library in your python 3 environment.

Nate
  • 2,113
  • 5
  • 19
  • 25
0

Another answer was found here: https://stackoverflow.com/a/4910393/1580659

pipVERSIONNUMBER install will install the library to the correct version of Python.

$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Community
  • 1
  • 1
JeremyE
  • 1,368
  • 4
  • 20
  • 40