Updated spyder but packages are disappearing - python

I updated my spyder from 3.3.6 to 4.0.1 and since then my libraries are not getting compiled , like pandas library, sklearn , and few other .
I don't know why it's happening . Normal import statements show error . Even numpy did the same , so i just ran pip install numpy in the ipython console and then it got solved .
Is there no other alternative? Spyder 3.6 worked just fine without running the pip command in the ipython console .
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
for now i used ipython commands to install the entire library again (pip install sklearn).
Can someone help me out with a permanent fix?

Related

ModuleNotFoundError: No module named 'sksurv' in python

I am trying to run survival analysis in python (pycharm) in linux, here is a part of the code
import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import train_test_split
from sksurv.datasets import load_flchain
from sksurv.linear_model import CoxPHSurvivalAnalysis
I get the error "ModuleNotFoundError: No module named 'sksurv'", I tried everything, but nothing works.
The required dependencies for scikit-survival,
cvxpy
cvxopt
joblib
numexpr
numpy 1.12 or later
osqp
pandas 0.21 or later
scikit-learn 0.22
scipy 1.0 or later
...will be automatically installed by pip when you run:
pip install scikit-survival
However, one module in particular, osqp, has CMake as one of its dependencies. If you don't have CMake installed, pip install scikit-survival will throw an error and the installation will fail.
You can download CMake for your OS at cmake.org/download
After CMake has installed, you should be able to successfully run
pip install scikit-survival
Notes:
GCC needs to be installed also
scikit-survival works with Python 3.5 or higher
More information is available in the docs

How to Import Pandas Profiling [duplicate]

I am new to pandas_profiling and getting ImportError while importing it. Please help.
import numpy as np
import pandas as pd
import pandas_profiling
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline
import seaborn as sns
After executing the above code in jupyter notebook, I am getting the following error.
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
> python --version
Python 3.7.3
> pip list | grep -E "matplotlib|pandas"
matplotlib 3.2.0
pandas 0.25.3
pandas-profiling 2.5.3
I don't know the actual reason but I restarted the kernel and it is working.
Before restarting the kernel I executed following commands:
conda install -c anaconda pandas-profiling

ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base'

I just want to do a linear regression with scikit-learn. When I try to import the linear model package the error message from the title appears.
I tried to follow the solution from a similar problem (link). The suggestion is basically to just get rid of the part of the code where it requests for the "MultipleOutputMixin" thingy.
When I do this, of course the MultiOuputMixin is no longer the problem, but it derives in an error at the line marked as 22 in the error message shown below.
Any ideas on what can I do to avoid the problem?
Thanks in advance for your help! :)
Python version = 3.70
scikit-learn verion = 0.21.2
This is what I'm doing:
from sklearn import linear_model
This is the error that I get:
ImportError Traceback (most recent call last)
<ipython-input-46-1c4d4ebecc3f> in <module>()
1 # Select a linear
----> 2 from sklearn import linear_model
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\__init__.py in <module>()
13
14 from .bayes import BayesianRidge, ARDRegression
---> 15 from .least_angle import (Lars, LassoLars, lars_path, lars_path_gram, LarsCV,
16 LassoLarsCV, LassoLarsIC)
17 from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\least_angle.py in <module>()
18
19 from .base import LinearModel
---> 20 from ..base import RegressorMixin, MultiOutputMixin
21 from ..utils import arrayfuncs, as_float_array, check_X_y
22 from ..model_selection import check_cv
ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base' (C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\base.py)
I have encountered a similar problem. I could solve by opening a new IPython console.
I don't think so it's a good idea to modify library related files without understanding it fully. I got this issue when I had updated scikit learn package. It worked after I launched a new shell.
!pip install scikit-learn==0.18.2 is the wrong advice.
You'll need scikit-learn version 0.22 or higher.
This was solved after shutting down the existing notebook and reopening it from home page. It may need a restart is what I got to know.
uninstall and install the imblearn again :
pip install imblearn
with the updated sklearn packages this worked for me.
From installation anacoda prompt:
Installing collected packages: imblearn, scikit-learn
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 0.20.3
Uninstalling scikit-learn-0.20.3:
Successfully uninstalled scikit-learn-0.20.3
Successfully installed imblearn-0.0 scikit-learn-0.23.1
Problem reasons
This issue occurs when you tried to install a new version of scikit-learn, I encountered the same issue while trying to install sklearn (1.0) while an old scikit-learn version (0.22.2) was installed.
I encountered this problem, because I had to update the version of sciki-learn on Colab and retrain my model to avoid some warnings with the production environment. The problem was as shown below:
UserWarning: Trying to unpickle estimator TfidfVectorizer from version 0.22.2.post1 when using version 1.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
So, when I did this:
!pip install scikit-learn==1.0
I got the error below while importing the following libraries:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
This is the rrror:
ImportError: cannot import name '_OneToOneFeatureMixin' from 'sklearn.base' (/usr/local/lib/python3.7/dist-packages/sklearn/base.py)
How to fix it
This problem can be fixed by simply trying to restart the runtime environment, or open a new notebook (runtime env restart by default as mentioned by AnandOCF)
This worked for me.
Activate your conda env
conda activate 'your_env_name'
Install imblearn library using pip if you haven't
pip install imblearn
Again install imbalanced-learn library using conda
conda install -c conda-forge imbalanced-learn
Then, you should be able to import without any errors.
You can run the following command on your notebook to solve the issue:
!pip install scikit-learn==0.18.2

Why am I unable to import the gensim module that has definitely been installed?

I have installed the gensim module for MAC by passing the following command in my Terminal:
pip3 install gensim
I already have many other modules such as pandas and numpy that have been installed but I am able to import the same to my Jupyter Notebook without any issues.
This is how I am importing gensim:
from gensim.models import Word2Vec
from gensim.models import KeyedVectors
So I checked the path where the 2 modules have been installed through the terminal, these being the same for a module I am able to import such as pandas as well as for gensim.
pip3 show pandas
pip3 show gensim
In both the cases I get the same output:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
Can anyone tell me what could be the issue in this case?

Python statsmodels and simple exponential smoothing in Jupyter and PyCharm

I am new to python, and trying to run this example in Jupyter notebook. Whenever I run following
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.api import SimpleExpSmoothing
It gives me following error
ImportError Traceback (most recent call last)
<ipython-input-5-a15788c08ca7> in <module>()
3 import pandas as pd
4 import matplotlib.pyplot as plt
----> 5 from statsmodels.tsa.api import SimpleExpSmoothing
ImportError: cannot import name 'SimpleExpSmoothing'
Although, I have installed statsmodels (0.8.0) by
pip install statsmodels
like other packages (numpy, pandas etc.). I checked on git, api file contains this method but my api file (obtained through pip) doesn't have this method. Maybe I am not getting the git version (seems latest one) through pip? I am working in windows and I also tried on mac OSX, and result is same. I tried to do a copy/paste attempt for missing files/code in files from git (not a good way) but it doesn't help. I would appreciate your suggestions here.
EDIT
So the solution for Jupyter (thanks to #user333700) is to install master branch directly from git by
pip install git+https://github.com/statsmodels/statsmodels.git
I am extending my question for PyCharm, how can I add a git package within PyCharm? This link does not help.
For future reference another solution which worked for me is to pip install the latest version directly:
pip install statsmodels==0.9.0rc1

Categories

Resources