I am a total newbie in Python 3 and programming in general so I looked at other peoples code and just for the beginning paste one example into Jupyter. But right at the beginning, I get an Error "ModuleNotFoundError: No module named 'xgboost'" Why does this not work?
import pandas as pd
import numpy as np
import re
import sklearn
import xgboost as xgb // error
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools as tls
import warnings
warnings.filterwarnings('ignore')
# Going to use these 5 base models for the stacking
from sklearn.ensemble import (RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, ExtraTreesClassifier)
from sklearn.svm import SVC
from sklearn.cross_validation import KFold
I am assuming you are running Anaconda, because this is the first error you encountered. You need to install this package: https://anaconda.org/anaconda/py-xgboost because the code you copied uses it and needs it.
You will probably get a plotly error too, so install https://anaconda.org/plotly/plotly and remember to restart Jupyter (or the kernel at least).
If you are not running Anaconda, run pip install xgboost and pip install plotly.
I tried
pip install xgboost
and
pip3 install xgboost
But it doesn't work
##ModuleNotFoundError: No module named 'xgboost'
It worked in the Jupyter Notebook cell
import sys
!{sys.executable} -m pip install xgboost
Go to command prompt >> By typing "cmd" in your windows search engine.>> Please type "pip install xgboost".
Later, close your Jupyter notebook and open it again. Run the respective cell.
If you are still getting the error then :
Add a cell in Jupyter notebook and type "pip install xgboost". Run this cell. Now it will work.
Giving a very detailed answer since beginners might be here too. Hope this helps! Be motivated! You can do it!
conda install -c conda-forge xgboost
Related
I am running scikit-learn 0.24.2 on the intelpython3_full conda distribution.
I am trying to run:
from sklearn.model_selection import HalvingGridSearchCV
and get the following error:
ImportError: cannot import name 'HalvingGridSearchCV' from 'sklearn.model_selection'
I am trying to run it from jupyter notebook.
Already tried reinstalling scikit-learn:
conda uninstall scikit-learn
conda install scikit-learn -c intel
Also tried:
-c conda-forge
Always get this error. Other imports with sklearn, for instance GridSearchCV work.
Can someone help me with this?
This must be run first:
from sklearn.experimental import enable_halving_search_cv
and then this:
from sklearn.model_selection import HalvingGridSearchCV
I tried to import umap in my jupyter notebook but had the following error:
ImportError: cannot import name 'structref' from 'numba.experimental' (C:\Users\name\Anaconda3\lib\site-packages\numba\experimental\__init__.py)
I tried to update conda but doesn't work. What can I do ?
The numba.experimental subpackage was added in version 0.51.0. You can check your version of number using:
import numba
numba.__version__
If it is less then 0.51.0, you will need to install a newer version.
conda install numba=0.51.*
I'm trying to use the seaborn module in jupyter notebook,I alredy installed all the dependecies and the seaborn too,but when I try to run,it's said that it does not have a module seaborn installed
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ed806232820c> in <module>
1 import pandas as pd
2 import matplotlib.pyplot as plt
----> 3 import seaborn as sns
ModuleNotFoundError: No module named 'seaborn'
Try restarting notebook first.
Make sure that seaborn is installed by same python interpreter used in the notebook.
Easiest way to be certain of this is to run
!pip install --user seaborn in the active notebook (! allows you to run shell command from your notebook)
Additional info for detecting the cause of the problem
You can check which interpreter is used by the notebook by running:
import sys
print(sys.executable)
I assume pip you used initially is not used by python you used to run the notebook (multiple python installations of the system or conda).
To specify which python is used for pip install you can run
<python-path> -m pip install seaborn where <python-path> is output of sys.executable.
I installed scikit-learn both using pip and conda commandas. Whenever I check the package, it shows that it is already installed but, whenever I try import it, it shows error.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
%matplotlib inline
ERROR:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-33-82d3fc6531ea> in <module>
3 import matplotlib.pyplot as plt
4 import seaborn as sns
----> 5 from sklearn.model_selection import train_test_split
6 get_ipython().run_line_magic('matplotlib', 'inline')
ModuleNotFoundError: No module named 'sklearn'
I have tried reinstalling it multiple times but it shows the same error
Make sure that if you install the sklearn package in the python version that you are working. For suppose if your system has two versions of python installed in it like both python 2 and python 3 then you have installed sklearn package in python 2 and executing your code in python 3 or vice-versa.
I think you don't have latest version of sklearn because in old version of sklearn
below code was not working.
from sklearn.model_selection import train_test_split
Please update your sklearn by following command
conda update scikit-learn
I got the same error while installing these.
What you can do is install all the packages using the command
conda install pandas
and all other packages similarly or all in once
conda install pandas numpy matplotlib scikit-learn
in your project directory.
And now you can open your jupyter notbook using command
jupyter notebook
in the same environment or I should say same project directory.
I'm running iPhyton Notebooks and I'm trying to import the Seaborn package. When I try to import it from the Terminal, it loads up fine, but when I import it through iPython Notebooks, it give me the following error.
I have even tried to re-install Seaborn using both Conda and Pip inside iPython notebooks and still it wont work.
Any idea why?
Thanks.
ImportError Traceback (most recent call last)
<ipython-input-1-417274a1ae6c> in <module>()
1 get_ipython().system(u'conda install seaborn')
2 get_ipython().system(u'pip install seaborn')
----> 3 import seaborn as sb
4
ImportError: No module named seaborn
Try this
import sys
print sys.path
sys.path.append('<path to package in your syste>')
import seaborn
In my Ubuntu 14.4LTS the packages get installed in the following folder
/usr/local/lib/python2.7/dist-packages
So I simply add the package path at run time
Donit install Ipython on all your system. Install it only in the environments you want it. Otherwise Ipython will look for modules in the default path instead of the environment's path.
This is probably where your ipython is looking:
/home/user/anaconda2/lib/python2.7/
It should be looking for modules here:
/home/user/anaconda2/envs/name-of-env/lib/python3.4/
To check the path you type:
import sys
sys.path
Try entering the following in your terminal:
conda install seaborn
It will install seaborn and make it available for you to import into your notebook
Open anaconda prompt and Type
pip install seaborn