Posts: 4
Threads: 2
Joined: Oct 2019
I am trying to install some packages to my Windows Python 3.7
I downloaded BeautifulSoup, and then from the Windows cmd prompt, in the directory where the BS setup file exists, I ran python setup.pl install
This seemed to execute with no errors and completed.
However, when I use this in a script:
1 |
from bs4 import BeautifulSoup
|
I get this error:
File "c:/myscripts/test.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I've tried numerous packages but they all give similar errors.
Thanks in advance for your help.
I've tried
Posts: 7,315
Threads: 123
Joined: Sep 2016
Oct-02-2019, 02:48 PM
(This post was last modified: Oct-02-2019, 02:49 PM by snippsat.)
TSheets13 Wrote:python setup.pl install That's not the way we do it anymore,all is done bye pip .
Look at Python 3.6/3.7 and pip installation under Windows
Then it should work like this,i use virtual environment in this demo as i already have it installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
(forum_env) E:\div_code\forum_env
λ python - V
Python 3.7 . 3
(forum_env) E:\div_code\forum_env
λ pip - V
pip 19.2 . 3 from e:\div_code\forum_env\lib\site - packages\pip (python 3.7 )
(forum_env) E:\div_code\forum_env
λ pip install beautifulsoup4
Collecting beautifulsoup4
Downloading .....
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4 - 4.8 . 0 soupsieve - 1.9 . 4
(forum_env) E:\div_code\forum_env
λ python
Python 3.7 . 3 (v3. 7.3 :ef4ec6ed12, Mar 25 2019 , 21 : 26 : 53 ) [MSC v. 1916 32 bit (Intel)] on win32
Type "help" , "copyright" , "credits" or "license" for more information.
>>> import bs4
>>> bs4.__version__
'4.7.1'
>>> from bs4 import BeautifulSoup
>>>
|
Posts: 4
Threads: 2
Joined: Oct 2019
Oct-02-2019, 03:10 PM
(This post was last modified: Oct-02-2019, 03:10 PM by TSheets13.)
I seem to be unable to use pip
C:\Users\tsheet\Downloads\beautifulsoup4-4.8.0>pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in c:\program files\python37\lib\site-packages\beautifulsoup4-4.8.0-py3.7.egg (4.8.0)
Requirement already satisfied: soupsieve>=1.2 in c:\program files\python37\lib\site-packages\soupsieve-1.9.4-py3.7.egg (from beautifulsoup4) (1.9.4)
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)'))) - skipping
Likely network security issue.
But interstingly I can get to https://pypi.org/simple/pip/ via the web browser. I followed instructions on downloading and installing packages manually. It does look like it satisfied some if not all requirements. But it still doesn't find bs4
Posts: 212
Threads: 25
Joined: Aug 2019
Oct-02-2019, 03:34 PM
(This post was last modified: Oct-02-2019, 05:37 PM by newbieAuggie2019.)
ATTENTION!!! THIS IS A COMPLETELY NEW AND DIFFERENT POST FROM THE PREVIOUS ONE HERE, BECAUSE I INADVERTENTLY ERASED THE PREVIOUS ONE WHILE TRYING TO ADD SOME COMMENTS!!!
I'm going to try to write again more or less what I had posted before with some added modifications ...
I'm going to explain, step by step, once again, how I installed BeautifulSoup. It is better to use pip:
1) I went to:
https://pypi.org/project/beautifulsoup4/
where on top of the page, you can see beautifulsoup4 4.8.0, and underneath that, pip install beautifulsoup4. Beside that, you can see an icon looking like two papers sheets, one on top of the other. If you click on this icon, you copy the command pip install beautifulsoup4 to your clipboard. (I prefer to do it this way, just in case I mistype something).
2) Now, on Windows cmd prompt, paste pip install beautifulsoup4 (or type directly if you prefer, pip install beautifulsoup4) and press the " ENTER" (or " RETURN") key and wait till the installation of beautifulsoup4 is completed:
3) Now, as the previous program I had here, didn't seem to look for the desired word, I looked for more information, and on this site:
https://stackoverflow.com/questions/3339...n/33397525
I found an example program written in some Python 2. I adapted it to Python 3, and also made some changes to small bits that produced errors before. Now, no warnings or errors are produced. Forget about the previous program I had here, and use this other one. Copy and save this modified program, from the original one on that site:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from bs4 import BeautifulSoup
import re
data =
searched_word = 'sunny'
soup = BeautifulSoup(data, 'html.parser' )
results = soup.body.find_all(string = re. compile ( '.*{0}.*' . format (searched_word)), recursive = True )
print ( 'Found the word "{0}" {1} times\n' . format (searched_word, len (results)))
for content in results:
words = content.split()
for index, word in enumerate (words):
if word = = searched_word:
print ( 'Whole content: "{0}"' . format (content))
before = None
after = None
if index ! = 0 :
before = words[index - 1 ]
if index ! = len (words) - 1 :
after = words[index + 1 ]
print ( '\tWord before: "{0}", word after: "{1}"' . format (before, after))
|
4) Now, when I execute it, it produces the following output:
Output: Found the word "sunny" 4 times
Whole content: "today is a sunny day"
Word before: "a", word after: "day"
Whole content: "I love when it's sunny outside"
Word before: "it's", word after: "outside"
Whole content: "
Call me sunny
"
Word before: "me", word after: "None"
Whole content: "sunny is a cool word sunny"
Word before: "None", word after: "is"
Whole content: "sunny is a cool word sunny"
Word before: "word", word after: "None"
>>>
I hope it helps.
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Posts: 7,315
Threads: 123
Joined: Sep 2016
Try:
1 |
python - m pip install - - trusted - host pypi.python.org - - trusted - host files.pythonhosted.org - - trusted - host pypi.org - - upgrade pip
|
Directly install.
1 |
pip install - - trusted - host = pypi.org - - trusted - host = files.pythonhosted.org beautifulsoup4
|
Bug, bug.
Using proxy.
1 |
pip install - - proxy = http: / / yourproxy:yourport beautifulsoup4
|
Posts: 212
Threads: 25
Joined: Aug 2019
Oct-02-2019, 03:42 PM
(This post was last modified: Oct-02-2019, 05:40 PM by newbieAuggie2019.)
(Oct-02-2019, 03:10 PM)TSheets13 Wrote: I seem to be unable to use pip
C:\Users\tsheet\Downloads\beautifulsoup4-4.8.0>pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in c:\program files\python37\lib\site-packages\beautifulsoup4-4.8.0-py3.7.egg (4.8.0)
Requirement already satisfied: soupsieve>=1.2 in c:\program files\python37\lib\site-packages\soupsieve-1.9.4-py3.7.egg (from beautifulsoup4) (1.9.4)
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)'))) - skipping
Likely network security issue.
But interstingly I can get to https://pypi.org/simple/pip/ via the web browser. I followed instructions on downloading and installing packages manually. It does look like it satisfied some if not all requirements. But it still doesn't find bs4 Hi!
I used to have also a lot of problems while I had Python not in the root directory. So I would advise you to write pip install beautifulsoup4 just after C:\> in your Windows cmd prompt. I would say that your system gets lost trying to find something among all those folders and subfolders ...
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Posts: 4
Threads: 2
Joined: Oct 2019
I have discovered that if I save the python file and execute it from the command line with python, it works just fine. All libraries are found. It's when I try to use an IDE like IDLE or PyCharm it doesn't work. Perhaps I need to configure something in the IDE's that I missed.
Posts: 7,315
Threads: 123
Joined: Sep 2016
Oct-02-2019, 06:12 PM
(This post was last modified: Oct-02-2019, 06:12 PM by snippsat.)
(Oct-02-2019, 05:52 PM)TSheets13 Wrote: All libraries are found. It's when I try to use an IDE like IDLE or PyCharm it doesn't work. Perhaps I need to configure something in the IDE's that I missed. Configure a Python interpreter
When talking about interpreter,it's the location of python.exe or folder it's in.
So if do this get the path to python version that work from command line,then set same version in configure link.
1 2 3 4 5 6 7 |
C:\>python - c "import sys; print(sys.executable)"
C:\python37\python.exe
C:\>pip - V
pip 19.2 . 3 from c:\python37\lib\site - packages\pip (python 3.7 )
C:\>
|
|