Can't import pytorch_lightning on Google colab - google-colaboratory

I'm using !pip install git+https://github.com/PyTorchLightning/pytorch-lightning
but when I'm importing pytorch_lightning I get the following error:
ImportError: cannot import name '_RequirementAvailable' from 'pytorch_lightning.utilities.imports' (/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/imports.py)
It all worked fine a week ago...

When you install Lightning as
pip install git+https://github.com/PyTorchLightning/pytorch-lightning
you get the latest version in development. It is not an official release. I recommend installing
pip install pytorch-lightning
to get the latest stable release. I suspect this will solve your import error.

Related

What is the working combination of the s3fs and fsspec version? ImportError: cannot import name 'maybe_sync' from 'fsspec.asyn'

I am using the latest version of s3fs-0.5.2 and fsspec-0.9.0, when import s3fs, encountered the following error:
File "/User/.conda/envs/py376/lib/python3.7/site-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/User/.conda/envs/py376/lib/python3.7/site-packages/s3fs/core.py", line 11, in <module>
from fsspec.asyn import AsyncFileSystem, sync, sync_wrapper, maybe_sync
ImportError: cannot import name 'maybe_sync' from 'fsspec.asyn' (/User/.conda/envs/py376/lib/python3.7/site-packages/fsspec/asyn.py)
what is a working combination version of s3fs and fsspec?
The latest version of s3fs and fsspec as of today is 2021.11.0. The latest version on conda-forge is 2021.10.1 . Since the change to calendar versioning this year, the two are always released together and the dependency pinned, so that this kind of problem won't occur in the future.
I believe for fsspec 0.9.0, you need s3fs 0.6.0 .
In my case the same happened. 'maybe_sync' was missing from 'fsspec.asyn'. For me, the following worked.
!pip install --upgrade awscli
!pip install --upgrade boto3
!pip install --upgrade git+https://github.com/dask/s3fs

Python, Pandas datareader and Yahoo Error RemoteDataError: Unable to read URL

I am trying to download historical data from Yahoo using Pandas datareader. This is the code that I normally use:
import pandas_datareader as pdr
df = pdr.get_data_yahoo('SPY')
However, I started receiving this error today: RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/SPY/history?period1=1467511200&period2=1625277599&interval=1d&frequency=1d&filter=history
Does anyone know how to solve it?
Thank you very much in advance!
This has been answered here already. Since now requires headers, pandas and pandas-datareader must be updated. Other libraries working with pdr might give you issues until gets updated or you modify the part of the code which retreives data.
Have a nice day ;).
pip install --upgrade pandas
pip install --upgrade pandas-datareader
If you are using Colab, run:
!pip install --upgrade pandas-datareader
...
Installing collected packages: pandas-datareader
Attempting uninstall: pandas-datareader
Found existing installation: pandas-datareader 0.9.0
Uninstalling pandas-datareader-0.9.0:
Successfully uninstalled pandas-datareader-0.9.0
Successfully installed pandas-datareader-0.10.0
WARNING: The following packages were previously imported in this runtime:
[pandas_datareader]
You must restart the runtime in order to use newly installed versions.
Go to Runtime -> Restart runtime. Then you can import pandas_datareader and check that it's the right version:
import pandas_datareader
pandas_datareader.__version__ # Should show 0.10.0

XLNetTokenizer requires the SentencePiece library but it was not found in your environment

I am trying to implement the XLNET on Google Collaboratory. But I get the following issue.
ImportError:
XLNetTokenizer requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the
installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones
that match your environment.
I have also tried the following steps:
!pip install -U transformers
!pip install sentencepiece
from transformers import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased-spiece.model')
Thank you for your help in advance.
After the
!pip install transformers and
!pip install sentencepiece
please restart your runtime and then execute all other codes.
I got the same error in google colab. Restarting the runtime did it for me.

ImportError Cannot import name 'warnings' from 'matplotlib.dates

Alpaca backtrader plot issue: I ran into this import issue and found this article, so I applied the code, but same issue not resolved. any one can help please?
My installed matplotlib version is 3.3.1
backtrader 1.9.76.123
python 3.8.5
the entire code posted below:
from matplotlib.dates
import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,MONTHS_PER_YEAR,
DAYS_PER_WEEK,SEC_PER_HOUR, SEC_PER_DAY,num2date, rrulewrapper,
YearLocator,MicrosecondLocator)
import alpaca_backtrader_api
import backtrader as bt
from datetime import datetime
#import matplotlib
ALPACA_API_KEY = "XXXXX"
ALPACA_SECRET_KEY = "XXXX"
ALPACA_PAPER = True
class SmaCross(bt.SignalStrategy):
def init(self):
sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
crossover = bt.ind.CrossOver(sma1, sma2)
self.signal_add(bt.SIGNAL_LONG, crossover)
cerebro = bt.Cerebro()
cerebro.addstrategy(SmaCross)
store = alpaca_backtrader_api.AlpacaStore( key_id=ALPACA_API_KEY,secret_key=ALPACA_SECRET_KEY,paper=ALPACA_PAPER)
if not ALPACA_PAPER:
broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker()
cerebro.setbroker(broker)
DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData
data0 = DataFactory(dataname='AAPL', historical=True, fromdate=datetime(2015, 1, 1), timeframe=bt.TimeFrame.Days)
cerebro.adddata(data0)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.plot()
Downgrade to matplotlib 3.2.2 until the bug in backtrader is fixed.
Here is the fix pull request: https://github.com/mementum/backtrader/pull/418.
pip uninstall matplotlib # or conda
pip install matplotlib==3.2.2
I suffered the same problem like you did, your link provided has the perfect solution. just get rid of warnings from locator.py
https://community.backtrader.com/topic/981/importerror-cannot-import-name-min_per_hour-when-trying-to-plot/8
I couldn't install matplotlib==3.2.2 nor the patch without uninstalling backtrader first.
So, this worked for me in the end:
Uninstall backtrader:
pip uninstall backtrader
Install the patch provided in the above solution:
pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
If necessary, install matplotlib again:
pip install matplotlib
As pointed out above, the issue is addressed in this pull request and the patch is the latest commit to master, but there hasn't been a release since 2019-05.
You can install the patched version like so:
pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
You could alternatively specify the required commit in requirements.txt like so:
-e git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
…then pip install -r requirements.txt
After installing with either method, you can confirm the versions installed with pip freeze:
...
backtrader==1.9.76.123
...
How to install from git
Mac Big Sur
for me it only worked if:
Downgrade python3.9 to python 3.8
then I downgraded matplotlib==3.2.2
For both python 3.8.x and 3.9.x, I solved the problem by using specific version of matplotlib==3.2.2
pip install matplotlib==3.2.2
By default, I used matplotlib==3.4.x version and the problem occured.
All of the above answers are fine. The problem is not with Matplotlib though. The Backtrader library hasn't kept up with the Matplotlib updates. You can do the off-label Backtrader update suggested by Joel Brigate above...or you can make a simple mod to locator.py file (backtrader.plot):
Just change:
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR,
SEC_PER_MIN, MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR,
SEC_PER_DAY, num2date, rrulewrapper, YearLocator,
MicrosecondLocator, warnings)
to:
from matplotlib import warnings
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR,
SEC_PER_DAY, num2date, rrulewrapper,
YearLocator, MicrosecondLocator)
You'll note that the warnings import now comes directly out of matplotlib rather than matplotlib.dates. This is the offending issue within locator.py.
Here is my solution:
python -m pip uninstall matplotlib
python -m pip uninstall backtrader
python -m pip install backtrader
python -m pip install matplotlib==3.2.2
Enjoy!
I could not install matplotlib==3.2.2 with python 3.9 .
Here is how did I fix this issue:
$ pip uninstall backtrader
$ pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
Reference:
Github: Fix ImportError from matplotlib.dates
#418
Mac Big Sur. I did the same: python 3.8.5, uninstall matplotlib, install matplotlib==3.2.2
I'm new at this so I first tried the easy way, through anaconda.org, but could not find version 3.2.2. Then tried it from the Jupyter notebook with conda install... didn't work. I finally did it straight through terminal, which worked fine.
#laffuste solution of downgrading to version 3.2.2 of matplotlib solved the issue for me. PR to fix the issue is still open, you can also follow this forum for more info on the problem:

Error installing pandas with pip: Could not find a version that satisfies the requirement numpy==1.9.3

I'm trying to install pandas. When I run: pip install pandas in cmd, I get the following error message: Could not find a version that satisfies the requirement numpy==1.9.3. Not sure how to fix this.
It's likely you have a different version of numpy installed, try upgrade numpy first with:
pip install numpy==1.9.3 --upgrade
then run pip install pandas. Also check this github issue. Maybe your python version is not supported.