简体   繁体   中英

Can't import third party libraries python3

I downloaded requests and BeautifulSoup modules using pip and when i try to import using command line it works. But when I code in notepad++ and then run the .py file using cmd it gives an error.

This is my code:

import requests
from bs4 import BeautifulSoup
response=requests.get('')
html=response.text
soup=BeautifulSoup(html,'html.parser')
soup.p.a.string

The error I am getting is:

Traceback (most recent call last):
  File "soup.py", line 1, in <module>
    import requests
  File "C:\Users\person8565\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\__init__.py", line 43, in <module> 
    import urllib3
  File "C:\Users\person8565\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "C:\Users\person8565\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
    import logging
  File "C:\Users\person8565\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 28, in <module>
    from string import Template
  File "C:\Users\person8565\Documents\python\string.py", line 13

     ^
SyntaxError: unexpected EOF while parsing

Can anyone tell me what I am doing wrong?

Quite simply you have named your file string.py . string is a module that is included in the default library. There is nothing wrong with any of the modules you imported only that you importing your own script and not the module it actually needs.

Rename string.py to anything that is not a name that is not a module in the default library and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM