I am trying to run the below code:-
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()
it does not throws any error but i realized pickle module is not installed. I went to install it via pip and getting below error:-
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
I tried google'd about it but did not get a solution. Please help. How do we install pickle in python 3.6(32-bit)
Pickle is a module installed for both Python 2 and Python 3 by default. See the standard library for 3.6.4 and 2.7.
Also to prove what I am saying is correct try running this script:
This will print out the Pickle documentation showing you all the functions (and a bit more) it provides.
Or you can start the integrated Python 3.6 Module Docs and check there.
As a rule of thumb: if you can import the module without an error being produced then it is installed
The reason for the
No matching distribution found for pickle
is because libraries for included packages are not available via pip because you already have them (I found this out yesterday when I tried to install an integrated package).If it's running without errors but it doesn't work as expected I would think that you made a mistake somewhere (perhaps quickly check the functions you are using in the docs). Python is very informative with it's errors so we generally know if something is wrong.
Test your pickle quickly. pickle is a part of standard python library and available by default.
I had a similar error & this is what I found.
My environment details were as below: steps followed at my end
As per the documentation, apparently, python 3.7 already has the pickle package. So it does not require any additional download. I checked with the following command to make sure & it worked.
So,
pip install pickle
not required for python v3.7 for surepickle
module is part of the standard library in Python for a very long time now so there is no need to install it viapip
. I wonder if you IDE or command line is not messed up somehow so that it does not find python installation path. Please check if your%PATH%
contains a path to python (e.g.C:\Python36\
or something similar) or if your IDE correctly detects root path where Python is installed.You can pip install pickle by running command
pip install pickle-mixin
. Proceed to import it usingimport pickle
. This can be then used normally.