Install Beautiful Soup for Use with a Higher Version of Python (than default Mac OS)
I have just reinstalled python 2.7 onto my macbook pro (running OS 10.13.6 High Sierra) as I had inadvertently removed it, not realising that it was required. I also have Python 3.6.8 loaded on the same computer, and am working my way through "Automate the Boring Stuff" which requires Beautiful Soup for web scraping. The problem is that my Terminal indicates python v2.7.15 and is installing BS4 somewhere in that library but I'm needing it for python v3.6.8. I've updated the Setuptools to the most recent spec using:
python -m pip install --upgrade pip setuptools wheelIf I type "python3" into the command line in an attempt to get to v3.6.8 I get:
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.Everything I type after that gives me either a syntax error or if I type:
python --version
it returns:
Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'python' is not definedWhen I try to change the directory to the Downloads folder, I get this:
>>> cd /Users/User/Downloads
Traceback (most recent call last): File "<stdin>", line 1, in <module>
NameError: name 'cd' is not definedCan anyone advise what the issue is with the Command line? And moreover how do I now run the pip installer from the command line to install / direct the BS4 package in / to the python3.6.8 library?
It's probably really straight forward, however, I'm a bit of a newb here...
Thanks for your help.
2 Answers
If I type "python3" into the command line in an attempt to get to v3.6.8 I get:
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.Everything I type after that gives me either a syntax error
That's because the commands you're entering are being interpreted by Python, not your terminal. To get back to your normal terminal, enter quit().
how do I now run the pip installer from the command line to install / direct the BS4 package in / to the python3.6.8 library
It seems that when you reinstalled Python 2.7, its directories were added to your PATH environment variable before the Python 3 directories. When you enter python into your terminal, it'll look for an executable named python first in the current working directory, and then through each of the directories in your PATH. It executes the first match and stops looking.
I would recommend editing your PATH so the Python 3 directories are before your Python 2 directories. See editing PATH variable on mac.
I'm running Windows, and I have these two directories in my PATH for Python 3:
C:\Users\Admin\AppData\Local\Programs\Python\Python37\
C:\Users\Admin\AppData\Local\Programs\Python\Python37\ScriptsI need both, because the python executable is in the first directory, and the pip executable is in the second.
Alternatively, change directory in your terminal to where the pip executable is: cd [...]\Python\Python37\Scripts.
Now you can install Beautiful Soup 4 for Python 3: pip install beautifulsoup4
Thanks Gordon.
That's because the commands you're entering are being interpreted by Python, not your terminal. To get back to your normal terminal, enter quit()
Yes, that was an obvious error on my part. Thanks for setting me straight.
The issue of resetting the PATH to prioritise Python 3 over 2 will take a little bit of research; I found the linked post a little confusing, but it just means I have to do some reading.
What did work for me was simply typing pip3 install beautifulsoup4
I found this as I was looking for the file path for Python 3.6 and happened upon the readme.txt that lives in that versions Application folder. To wit:
Python 3 and Python 2 Co-existence: Python.org Python 3.6 and 2.7.x versions can both be installed on your system and will not conflict. Command names for Python 3 contain a 3 in them, python3 (or python3.6), idle3 (or idle3.6), pip3 (or pip3.6), etc. Python 2.7 command names contain a 2 or no digit: python2 (or python2.7 or python), idle2 (or idle2.7 or idle), etc.
So there it is.
But thanks for your help. You sent me in the right direction to be sure.