I tried to install statsmodels in python. After installation, I checked with pip freeze. The package can be seen in the list.
When I am trying:
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
I am getting error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name ExponentialSmoothing
I have tried the following link also :
link
As of today (10 May 2018), the problem is solved by simply installing version 0.9.0 rather than the default 0.8.0:
pip install statsmodels==0.9.0rc1
I met the same situation, and the install process recommended in Nish's url didn't work for me. Here's how did I solve the problem (I'm using Mac OS).
Remove statsmodels library first, if you have installed: pip uninstall statsmodels
In your terminal, type git init, to initiate git
Then type git clone git://github.com/statsmodels/statsmodels.git
Change the directory to statsmodels using “cd statsmodels”
Next type python setup.py install
python setup.py build_ext --inplace
Now type python in your terminal and then type from statsmodels.tsa.api import ExponentialSmoothing, to see whether it can import successfully
If using conda, this will make statsmodel 0.9.0
conda update statsmodels
It is the wrong import,
Try
from statsmodels.tsa.holtwinters import ExponentialSmoothing, SimpleExpSmoothing, Holt
You can follow the steps mentioned below:
Step 1: Remove statsmodel using pip uninstall statsmodel
Step 2: Install git from here: https://git-scm.com/downloads
Step 3: Follow steps mentioned under "Installing library(statsmodels)" from link mentioned below:
https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+AnalyticsVidhya+%28Analytics+Vidhya%29
Related
I am trying to install stable-baselines and run the first two lines from Getting Started section of the online manual but no option is working. I started with
pip install stable-baselines
Now when I run:
import gym
from stable_baselines.common.policies import MlpPolicy
I get
No module named 'tensorflow.contrib'
This apparently is because tensorflow version 2 doesn't have tensorflow.contrib. But version 2 was released in Sept 2019. Do I really have to use only tensorflow version 1?
What is the right way to install stable-baselines and run that simple example?
I tried
pip install stable-baselines3
in a virtual environment. This gives a different error:
In [2]: from stable_baselines.common.policies import MlpPolicy
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [2], in <module>
----> 1 from stable_baselines.common.policies import MlpPolicy
ModuleNotFoundError: No module named 'stable_baselines'
In [3]: from stable_baselines3.common.policies import MlpPolicy
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [3], in <module>
----> 1 from stable_baselines3.common.policies import MlpPolicy
ImportError: cannot import name 'MlpPolicy' from 'stable_baselines3.common.policies' (/home/raph/RL/stable-baselines/venv/lib/python3.8/site-packages/stable_baselines3/common/policies.py)
To quote the github readme:
Note: Stable-Baselines supports Tensorflow versions from 1.8.0 to 1.14.0. Support for Tensorflow 2 API is planned.
The same github readme also recommends to use stable-baselines3, as stable-baselines is currently only being maintained and its functionality is not extended. Thus, I would not expect the TF1 -> TF2 update any time soon.
If you can not install this version of tensorflow, I suggest to use stable-baselines3 and follow the examples. The code you posted above is not consistent with the stable-baselines3 docs, which import the MlpPolicy as
from stable_baselines3.sac.policies import MlpPolicy
According to the stable-baselines documentation you can only use Tensorflow version 1.8.0 to version 1.15.0.
If you want to run Tensorflow 1, and you want to use pip as your package manager, you'll need to install python version 3.7 or lower. I did the following in my ubuntu terminal
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7
sudo apt install virtualenv
virtualenv --python=/usr/bin/python3.7 <env-name>
source <env-name>/bin/activate
pip install tensorflow==1.15.0
...
Alternatively, you could try using this guide, which gives instructions as to how to migrate something to Tensorflow version 2.
I am importing train_test_split as:
from sklearn.model_selection import train_test_split and it is giving an error cannot import name 'comb'.
The versions I am using are scipy 0.18.1 and sklearn 0.17.1
Below is the detail of error, please guide here if you feel something is wrong.
Traceback (most recent call last):
File "<ipython-input-21-e45e815fd516>", line 1, in <module>
from sklearn import model_selection
File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\__init__.py", line 1, in <module>
from ._split import BaseCrossValidator
File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 31, in <module>
from ..utils.fixes import signature, comb
ImportError: cannot import name 'comb
The suggestion in the comment above worked for me.
scikit-learn version 0.17.1 doesn't have the 'model-selection' module (it has instead the 'cross_validation' module, reference here). Since you have Anaconda installed, trying to upgrade scikit-learn to the newest version using the pip installer may cause a mismatch with the installed scipy and numpy versions (upgrading them with the pip installer wont solve the problem). The solution is to upgrade all three libraries using anaconda's installer, but before that all existing versions must be uninstalled, first using pip (in case, like me, you already went the pip route) then using conda.
Following the suggestions in the referred link:
pip uninstall:
pip uninstall numpy scipy -y
pip uninstall scikit-learn -y
conda uninstall:
conda uninstall numpy scipy scikit-learn -y
conda install:
conda install numpy scipy scikit-learn -y
Don't forget to restart Anaconda before retrying your import clause.
I am very new to Python and want to add Numpy and Scipy module. I think my question is very simple for you. I am using Python 3.06a.1 version. I think I already installed something called Anaconda that contains those library. When I type import scipy I get the following message:
import scipy
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import scipy
ImportError: No module named 'scipy'
also when I want to installed with command line I get the following message which means that I have it already.
localhost:~ user$ pip install scipy
Requirement already satisfied (use --upgrade to upgrade): scipy in ./anaconda/lib/python3.5/site-packages
localhost:~ user$
Please help me to fix this problem
You shouldn't have problem with scipy and numpy if you installed Anaconda. What I'm advising you may sound stupid, but I'm sure it has a good chance to solve your problem.
Relaunch Anaconda, reboot your computer, reinstall Anaconda.
Edit : also watch out to use "scipy" and not "spicy" as I just witnessed in your logs.
if you are using anaconda, try installing scipy using anaconda:
conda install scipy
I was playing with the decision tree algorithm and trying to plot the tree. However the IDE reported following error:
Couldn't import dot_parser, loading of dot files will not be possible.
<class 'pandas.core.frame.DataFrame'>
Traceback (most recent call last):
File "C:/Users/s152730/Desktop/exe1.py", line 70, in <module>
graph = pydot.graph_from_dot_data(test.getvalue())
File "C:\Python27\lib\site-packages\pydot.py", line 220, in graph_from_dot_data
return dot_parser.parse_dot_data(data)
NameError: global name 'dot_parser' is not defined
I have no idea how to deal with this problem because I've tried to uninstall and reinstall both pydot dan pyparsing, which was proposed in other answers, but it didn't help.
Here is my code:
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import ExtraTreeClassifier
from sklearn import tree
from sklearn.externals.six import StringIO
import pydot
from IPython.display import Image
test = StringIO()
tree.export_graphviz(clf, out_file=test, feature_names = attribute_names)
graph = pydot.graph_from_dot_data(test.getvalue())
graph.writepng('test.png')
image(filename = 'test.png')
I am using python2.7 and running on PyCharm, the OS is win8.1.
Thanks for your help.
It seems your error is that you are missing part of a library (pyparsing) because of incorrect order of installation.
See here and here
Obvious to the initiated but not to the newbie: The workaround is to
install pyparsing < 2.0.0 prior to installing pydot (or a package
that depends on pydot.)
$ pip install pyparsing==1.5.7
The solution seems to be to first remove pydot and pyparsing, and then to install pyparsing first, then pydot.
The versions of which to install will most likely change in the future, so at the moment it seems you need to run something like the following: (taken from this lovely answer)
pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
pip install pydot
For me, I found a great tip is to install pydotplus instead, as it is compatible with pyparsing v2.0 and greater. It also has the advantage that it can work with the graphviz installation from Anaconda. I'm using Anaconda v2.4.1 and on Windows 7 x64 and Graphviz 2.38 installed using condas.
I've just update my pydotto 1.2.3, and the error disappears.
sudo pip install -U pydot
Using Python 2.7 with scikit-learn 0.14 package. It runs well on some examples from the user guild expect the Linear Models.
Traceback (most recent call last):
File "E:\P\plot_ols.py", line 28, in <module>
from sklearn import datasets, linear_model
File "C:\Python27\lib\site-packages\sklearn\linear_model\__init__.py", line 12, in <module>
from .base import LinearRegression
File "C:\Python27\lib\site-packages\sklearn\linear_model\base.py", line 29, in <module>
from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
ImportError: cannot import name inplace_column_scale
Thank you~
I was able to fix this by going to my python folder and deleting the file:
python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd
My guess is that the problem was:
An older version of scikit-learn implemented sparsefuncs as a windows DLL
The current version implements it as a python file
If you install a new version on top of an old version it does not delete the old DLL
When you try to import, Python uses the pyd in preference to the py implementation
But the old implementation did not include this function
This suggests that there might be bigger problems caused by installing a new version and it might be wise to delete the whole sklearn directory before reinstalling the new version.
I encountered the same issue in Mac Os.
I solved it by deleting the file manually:
rm /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so
Uninstalling scikit-learn and reinstalling it was the only option that worked for me:
pip uninstall scikit-learn
pip install scikit-learn
I solve this problem by :
pip uninstall scikit-learn
and don't forget to rm the 'sklearn' folder in the python 'site-packages'
rm -rf /path/Python-2.7.5/lib/python2.7/site-packages/sklearn/
then reinstall the package:
pip install scikit-learn
On a related note, this has been posted as a bug on the official Github page, along with some additional solutions, basically suggesting the same solutions as above. Long story short: run a make clean to get rid of the .so file.
I had the same problem. I had originally installed scikit-learn by:
sudo apt-get install python-sklearn
When none of the other solutions posted here worked, I decided to uninstall my version of scikit-learn and reinstall it:
pip2 install --user --install-option="--prefix=" -U scikit-learn
Used pip2 because I have two versions of python, so I use scikit-learn in Python 2.7
same problem happened with can not import _safe_split, have a look
http://stackoverflow.com/questions/41024001/importerror-cannot-import-name-safe-split
https://github.com/scikit-learn/scikit-learn/issues/7582
EDIT: check comment by Andreas Mueller