简体   繁体   English

无法导入第三方库python3

[英]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. 我使用pip下载了请求和BeautifulSoup模块,当我尝试使用命令行导入时,它可以工作。 But when I code in notepad++ and then run the .py file using cmd it gives an error. 但是当我在notepad ++中编码然后使用cmd运行.py文件时,它会出错。

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.py string is a module that is included in the default library. string是默认库中包含的模块 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. string.py重命名为任何不是默认库中的模块名称的名称,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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