I am very new to Python 3x, running on a mac.
Currently using a sentdex tutorial for python with finance, tried running the following script:
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2000,1,1)
end = dt.datetime(2016,12,31)
df = web.DataReader('TSLA', 'yahoo', start, end)
print(df.head())
However this returns the following error message:
Traceback (most recent call last):
File "F:\Downloads\Python Work\try figuring thigns out\finance\try.py", line 1, in <module>
import pandas_datareader.data as web
File "C:\Python36\lib\site-packages\pandas_datareader\__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "C:\Python36\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "C:\Python36\lib\site-packages\pandas_datareader\google\daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "C:\Python36\lib\site-packages\pandas_datareader\base.py", line 13, in <module>
from pandas_datareader._utils import (RemoteDataError, SymbolWarning,
File "C:\Python36\lib\site-packages\pandas_datareader\_utils.py", line 5, in <module>
from pandas.core.common import PandasError
ImportError: cannot import name 'PandasError'
I think maybe there's something wrong with panda-datareader itself, which I've ensured has been upgraded to most recent version (pandas-datareader 0.3.0.post0)
Is there an older version I can install instead? I've been using pip3 to install via mac terminal.
Thanks very much for any help!
I think you installed pandas v. 0.20.1 released yesterday.
pandas-datareader is still not compatible with this version, for the moment you should stay on pandas 0.19.2:
pip install -U pandas==0.19.2
The latest version of pandas_datareader (0.5.0) takes care of this import error. You can install it with pip:
sudo pip install -U pandas_datareader
I may already be too late to the discussion but I encountered this earlier today using a brand new Azure Compute that I spun up, I did all the steps above and was always encountering the error.
It may not be explicitly stated above but restarting the kernel AFTER the steps above fixed the issue.
Related
I've installed Pytorch and Torchvision in the way suggested on their website via pip within a virtual environment (env), and whilst no errors occur during installation when I go to import torchvision in my python code the following error occurs.
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import torchvision
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/__init__.py", line 2, in <module>
from torchvision import datasets
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/datasets/__init__.py", line 9, in <module>
from .fakedata import FakeData
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/datasets/fakedata.py", line 3, in <module>
from .. import transforms
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/__init__.py", line 1, in <module>
from .transforms import *
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 17, in <module>
from . import functional as F
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 5, in <module>
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/Users/QuinceyBee/env/lib/python3.7/site-packages/PIL/__init__.py)
I have tried creating new virtual environments to rebuild from scratch, tried to install via conda within a conda environment, however, neither of these resolved this issue.
I apologise for any format issues, this is the first time posting on here and also I'm relatively new to using python.
Any assistance would be greatly appreciated.
Pillow 7.0.0 removed PILLOW_VERSION, you should use version in your own code instead.
https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant
If using Torchvision, there is a release planned this week (week 2, 2020) to fix it:
https://github.com/pytorch/vision/issues/1712#issuecomment-570286349
The options are:
wait for the new torchvision release
use the master version of torchvision as given below
pip install -U git+https://github.com/pytorch/vision)
install torchvision from a nightly, which also requires a pytorch from a nightly version
or install Pillow<7
pip install "pillow<7"
New to Python. Trying to understand how to import the pandas module. I imported it through Pycharm, then ran a basic script seen below. I get several errors that I'm not sure how to interpret
import pandas
x = input("Enter your age")
print(x)
I receive this error message.
Traceback (most recent call last):
File "C:/Users/leeb/PycharmProjects/HelloWorld/app.py", line 1, in <module>
import pandas
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\pandas\__init__.py", line 11, in <module>
__import__(dependency)
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\__init__.py", line 150, in <module>
from . import random
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\random\__init__.py", line 181, in <module>
from . import _pickle
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "type.pxd", line 9, in init numpy.random.mtrand
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 440 from C header, got 432 from PyObject
This error tends to happen when you have an older version of Numpy installed.
You should upgrade it, as follows:
pip install numpy --upgrade
If that doesn't work, try to use a specific version of numpy, as follows:
pip uninstall numpy
pip install numpy==1.15.1
Or, if you're using anaconda, try:
conda update numpy
I want to get historic and current data stock prices from yahoo finance and/or google finance with python. To do so, I installed pandas and pandas_datareader on my machine. When I import pandas everything goes fine, but when I import pandas_datareader I get an error. More specifically, the following script
import pandas
import pandas_datareader
generates the following error
File "a.py", line 5, in <module>
import pandas_datareader
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
I tried to reinstall pandas_datareader, but It still doesn't work. Any idea what the problem might be? I use python3 on macBook Pro (beginning 2015) with macOS High Sierra Version 10.13.5.
Try this:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader
and let me know if it worked :)
I'm running Ubuntu 13.10 with Python 2.7.5+, and whenever I try to import the matplotlib package, I get an error. Specifically, my test script has only the following code:
#!/usr/bin/python
import matplotlib.pyplot as plt
When I run the test script, here is the error:
Traceback (most recent call last):
File "./test.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/usr/local/lib/python2.7/dist-packages/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath
File "/usr/local/lib/python2.7/dist-packages/matplotlib/textpath.py", line 22, in <module>
from matplotlib.mathtext import MathTextParser
File "/usr/local/lib/python2.7/dist-packages/matplotlib/mathtext.py", line 26, in <module>
from six import unichr
ImportError: cannot import name unichr
Any idea what I'm doing wrong?
You apparently have an outdated version of six.
The unichr wrapper was added in version 1.4.0, as seen in CHANGES. I'm not sure exactly when 1.4.0 was released, but the fix for issue #25 was committed on 2013-05-18, so… some time after that.
So, if you print(six.__version__), and it's anything less than '1.4.0', that's your problem.
Depending on whether you're installing packages with pip or with your system's package manager, the solution is going to be something like one of these:
$ pip install --upgrade six
$ apt-get install six
$ brew install --upgrade six
… etc.
But meanwhile, matplotlib shouldn't be requiring 1.3 but using features only available in 1.4. Your GitHub issue matplotlib#3538 should get this fixed.
I want to use Python for trying out hddm.
I installed anaconda, Python 2.7. When I try to follow the hddm tutorial in the command line window in spyder, the following happens, which seems to be a problem in pymc:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import hddm
Traceback (most recent call last):
File "<ipython-input-24-17365318b31c>", line 1, in <module>
import hddm
File "/Users/c/anaconda/lib/python2.7/site-packages/hddm/__init__.py", line 7, in <module>
import likelihoods
File "/Users/c/anaconda/lib/python2.7/site-packages/hddm/likelihoods.py", line 2, in <module>
import pymc as pm
File "/Users/c/anaconda/lib/python2.7/site-packages/pymc/__init__.py", line 31, in <module>
from .distributions import *
File "/Users/c/anaconda/lib/python2.7/site-packages/pymc/distributions.py", line 30, in <module>
from . import flib, utils
ImportError: cannot import name flib
I work on Mac OS X 10.7. On the web, I find some comments concerning pymc possibly not being compiled with the correct version of gfortran, but the solutions all seem to be for windows. Also, I thought that this kind of problem should not happen with an integrated system like Anaconda?
There are two options:
use conda install -c conda.binstar.org/pymc pymc
install gfortran and use pip install -U pymc