我正在尝试运行以下代码:
import bs4 as bs
import pickle
import requests
import lxml
def save_sp500_tickers():
resp = requests.get("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies")
soup = bs.BeautifulSoup(resp.text, "html5lib")
table = soup.find("table", { "class" : "wikitable sortable"})
# print(soup)
# print(soup.table)
tickers = []
for row in table.findAll("tr")[1:]:
ticker = row.findAll("td")[0].text
tickers.append(ticker)
with open("sp500tickers.pickle","wb") as f:
pickle.dump(tickers, f)
print(tickers)
# return tickers
# save_sp500_tickers()
它不会抛出任何错误,但我意识到未安装 pickle 模块。我尝试通过 pip 安装它并收到以下错误:-
D:\py_fin>pip install pickle
Collecting pickle
Could not find a version that satisfies the requirement pickle (from versions:
)
No matching distribution found for pickle
我们如何在 python 3.6(32 位)中安装 pickle?
原文由 satyaki 发布,翻译遵循 CC BY-SA 4.0 许可协议
pickle
模块 很长一段时间以来都是 Python 标准库的一部分,因此无需通过pip
安装它。我想知道您的 IDE 或命令行是否以某种方式搞砸了,以至于找不到 python 安装路径。请检查您的%PATH%
是否包含 python 的路径(例如C:\Python36\
或类似的东西)或者您的 IDE 是否正确检测到安装 Python 的根路径。