【问题标题】:Pydev shows Unresolved import but code worksPydev 显示未解决的导入,但代码有效
【发布时间】:2018-12-16 04:52:29
【问题描述】:

我在 Eclipse 上使用 Pydev。

这是我的代码

import pandas as pd
from urllib.request import urlopen
from http.client import RemoteDisconnected

xl_sheet = pd.read_excel('sample.xlsx', sheet_name='Sheet1')
for i in xl_sheet.index:
    web_url = xl_sheet['Web'][i]

    if isinstance(web_url, str):
        if 'http://' not in web_url:
            web_url = 'http://' + web_url
        print(web_url)

        try:
            code = urlopen(web_url).getcode()
        except RemoteDisconnected:
            print('not working')

Pydev 为 from http.client import RemoteDisconnected 这一行显示 unresolved import。但是当我运行代码时,它可以工作(它打印not working 用于少数已关闭的站点)。有什么问题?

【问题讨论】:

  • 是否有可能您安装了两个 Python,例如 3.4 和 3.5,并且 PyDev 配置为根据 3.4 标准库检查您的代码,但您在 3.5 下运行代码?因为 RemoteDisconnceted 是在 3.5 中添加的。
  • @abarnert 我正在为这个项目使用 virtualenv,并且为这个项目设置的解释器是没有添加到 PYTHONPATH 的外部文件的解释器。另外,语法和解释器一样

标签: python eclipse python-3.x pydev


【解决方案1】:

请尝试将http.client 添加到强制内置函数中,看看它是否能解决您的问题。

请参阅http://www.pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-ForcedBuiltins,了解有关如何实际执行此操作(以及如何使用)的详细信息。

【讨论】:

  • 不。它没有
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-20
  • 2012-02-04
  • 1970-01-01
  • 2011-11-09
  • 1970-01-01
相关资源
最近更新 更多