Here’s what to keep straight in your mind as you do Python assignments:
Zed (LPTHW) is all Python 2. Those of you on Mac OS: In any directory on your computer, when you type
python in Terminal, you will launch Python 2.7.x. No virtualenv for this.
Mitchell and all scraping exercises use Python 3. In Terminal, navigate into your scraping directory. There, activate your virtual environment:
BeautifulSoup is already installed there. You can run any Python file there, and it will run under Python 3.6.x, not 2.7.x. To run a file named foobar.py, for example:
(env) myname scraping$ python foobar.py
Remember, you don’t start Python to run programs that are in files.
When you get an error, first ask yourself: Am I in the correct Python environment? 2 or 3?
Second, make sure you are not in Python when you are trying to run a file. When you see >>> you are in Python. To run a file, you need to be at the bash prompt: $
To quit using the virtualenv:
(env) myname scraping$ deactivate