ImportError:没有名为xgboost的模块

min*_*niQ 24 python jupyter-notebook

当我尝试从python终端导入时,我得到了这个错误,虽然我按照所有步骤安装xgboost,不知何故python无法获取包详细信息.我对python相对较新,我可以轻松安装numpy和pandas包,我用过此链接可在MACOSX上安装http://xgboost.readthedocs.io/en/latest/build.html

>>> import xgboost
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   ImportError: No module named xgboost
Run Code Online (Sandbox Code Playgroud)

当我执行pip install xgboost时,我收到此错误,

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/h7/pyph_7qj6171tqp50cf2xc7m0000gn/T/pip-build-TEvbD6/xgboost/ 
Run Code Online (Sandbox Code Playgroud)

我在打印sys路径上得到这个,

print sys.path

['','/ System/Library/Frameworks/Pepy.framework/Version/2.7/lib/python27.zip','/ System/Library/Frameworks/Pepy.framework/Version/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin','/ System/Library/Frame /Python.framework/Version/7.7/lib/python2.7/plat -mac','/ System/Library/Frame /Python.framework/Version/2.7/lib/python2.7 /plat-make/lib -scriptpackages','/ System/Library/Frame /Python.framework/Version/2.7 /lib/python2.7/lib-tk','/ System/Library/Frame /Python.framework/Version/7.7/lib/python2.7/lib-old','/ System/Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/lib-dynload','/ Library /Python/2.7/site-package','/ System/Library/Frame /Python.framework/Version/7.7/Extra/lib/python ','/ System/Library/Frame /Python.framework/Version/7.7/Extras/lib/python/PepyB'

Moh*_*ANI 12

我遇到过同样的问题.我尝试了一切,但唯一对我有用的解决方案是直接从这里安装whl文件:http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost

然后你可以这样做:

pip install yourFile.whl
Run Code Online (Sandbox Code Playgroud)

在Windows上,我设法只需双击whl文件并安装它

祝好运


kil*_*les 11

首先,您需要控制您的python环境.下载自制的 python,将它们粘贴到一个新的终端窗口中

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run Code Online (Sandbox Code Playgroud)

在这里,您将被提示输入您的密码.安装homebrew后,安装python brew install python.请检查您的安装brew doctor并遵循自制的建议.

现在,使用新的终端窗口,从pip安装xgboost.打开终端并将其粘贴到:

pip install xgboost
Run Code Online (Sandbox Code Playgroud)


小智 8

我试过

pip install xgboost
Run Code Online (Sandbox Code Playgroud)

pip3 install xgboost
Run Code Online (Sandbox Code Playgroud)

但这不起作用

ModuleNotFoundError:没有名为“xgboost”的模块

最后我解决了 Try this in the Jupyter Notebook cell

import sys
!{sys.executable} -m pip install xgboost
Run Code Online (Sandbox Code Playgroud)

结果:

Collecting xgboost
  Using cached xgboost-1.4.1-py3-none-win_amd64.whl (97.8 MB)
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1
Run Code Online (Sandbox Code Playgroud)


Men*_*hao 7

仅供参考,如果您使用的是 anaconda dist'n 然后需要做

conda install -c conda-forge xgboost
Run Code Online (Sandbox Code Playgroud)


小智 7

在 Anaconda Powershell Prompt 中使用 conda install 然后使用 pip install

conda install -c conda-forge xgboost
pip install xgboost
Run Code Online (Sandbox Code Playgroud)


min*_*niQ 6

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
sudo cp make/minimum.mk ./config.mk;
sudo make -j4;
sh build.sh
cd python-package
python setup.py install
Run Code Online (Sandbox Code Playgroud)

Atleast现在我可以从macosx上的终端导入xgboost,我还没能在jupyter笔记本中导入它.


小智 5

尝试跑步

pip install xgboost
Run Code Online (Sandbox Code Playgroud)

在 Anaconda 提示符下;在 Anaconda 提示符下执行此操作很重要,因此它与您正在使用的 Python 位于同一位置。