0

I am a total newbie in Python 3 and programming in general so I looked at other people's code and just for the beginning paste one example into Jupyter. But right at the beginning, I get an Error saying:

ModuleNotFoundError: No module named 'xgboost'

This is my code below. 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
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
Da Nickste
  • 61
  • 1
  • 2
  • 8
  • Does this answer your question? [Jupyter python3 notebook cannot recognize pandas](https://stackoverflow.com/questions/40553560/jupyter-python3-notebook-cannot-recognize-pandas) – pyeR_biz Jul 25 '21 at 06:28
  • There definitely is a windows version. It would of been helpful if the other comments contains instructions if one IS running Anaconda. The link to install xgboost on python + Anaconda for Windows 64 is provided in the above comment (anaconda.org/anaconda/py-xgboost) (conda install -c anaconda py-xgboost ) – msarafzadeh Aug 06 '19 at 08:20

4 Answers4

1

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.

Filip Dimitrovski
  • 1,576
  • 11
  • 15
  • Yes, I do run Anaconda. Does this package has a windows version as well? Because I only saw osx and linux files. – Da Nickste Apr 12 '19 at 19:35
  • 1
    @DaNickste I modified my answer with a new xgboost package that has win64 support. https://anaconda.org/anaconda/py-xgboost – Filip Dimitrovski Apr 12 '19 at 20:32
  • Yes there definitely is a windows version. It would of been helpful if the answer contains instructions if one IS running Anaconda. The ink to install xgboost on python + Anaconda for Windows 64 is provided in the above comment (https://anaconda.org/anaconda/py-xgboost) (conda install -c anaconda py-xgboost ) – msarafzadeh Aug 05 '19 at 19:33
0

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
pyeR_biz
  • 986
  • 12
  • 36
Anj
  • 99
  • 5
  • 1
    Since you don't know it works -- I'm going to reccomend a couple of links for why it worked. You need to be aware of what an environment is, and what environment are you running your python kernel in, which packages are installed in that environment. https://stackoverflow.com/questions/40553560/jupyter-python3-notebook-cannot-recognize-pandas https://stackoverflow.com/questions/52877531/jupyter-notebook-modulenotfounderror/52877717#52877717 – pyeR_biz Jul 25 '21 at 06:31
  • try this ... !pip3 install xgboost – J R May 28 '22 at 17:54
0

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!

  • So the reason that works **from in the notebook** is because of environments that @pyeR_biz's comment is touching on below @Anj's answer. You've luckily triggered the new magics for pip and conda by not including anything in front of your `pip install`. This is because due to the automagics settings, Jupyter/IPython usually tries adding `%` in front of commands if you leave it off. The full command not relying on the `automagics` would be `%pip install xgboost`. See [here](https://discourse.jupyter.org/t/why-users-can-install-modules-from-pip-but-not-from-conda/10722/4?u=fomightez) for more. – Wayne Feb 17 '22 at 21:22
0
conda install -c conda-forge xgboost
Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
john
  • 1
  • 2
    Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch May 26 '22 at 19:45