简体   繁体   English

Jupyter 笔记本 xgboost 导入

[英]Jupyter notebook xgboost import

I have the problem below (I'm on a MAC)我有以下问题(我在 MAC 上)

I can import xgboost from python2.7 or python3.6 with my Terminal but the thing is that I can not import it on my Jupyter notebook.我可以使用我的终端从 python2.7 或 python3.6 导入 xgboost,但问题是我无法在我的 Jupyter 笔记本上导入它。

import xgboost as xgb

ModuleNotFoundError Traceback (most recent call last) in () ----> 1 import xgboost as xgb ModuleNotFoundError Traceback (最近一次调用最后一次) in () ----> 1 import xgboost as xgb

ModuleNotFoundError: No module named 'xgboost' ModuleNotFoundError: 没有名为“xgboost”的模块

Although I write :虽然我写:

!pip3 install xgboost

It prints that :它打印:

Requirement already satisfied: xgboost in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost) Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost)已满足要求:/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg 中的 xgboost 已满足要求:/Library/Frameworks/Python 中的 numpy .framework/Versions/3.6/lib/python3.6/site-packages (from xgboost) 要求已经满足:scipy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost)

Help please I searched everywhere :(请帮助我到处搜索:(

Within Jupyter Notebook cell, try running:在 Jupyter Notebook 单元中,尝试运行:

import sys !{sys.executable} -m pip install xgboost

This allows the package to be install with right on Jupiter notebook这允许在 Jupiter 笔记本上安装软件包

Running a shell escape !pip3 doesn't guarantee that it will install in the kernel you are running.运行 shell escape !pip3并不能保证它会安装在您正在运行的内核中。 Try:尝试:

import sys
print(sys.base_prefix)

and see if this matches either of your terminal pythons.看看这是否与您的终端 python 匹配。 You should be able to run <base_prefix>/bin/pip install <package> to ensure it is in the right site-packages .您应该能够运行<base_prefix>/bin/pip install <package>以确保它位于正确的site-packages

You can also look at which python your kernel is running by looking in kernel.json most likely in ~/Library/Jupyter/kernels/<kernel>/kernel.json .您还可以通过查看kernel.json最有可能在~/Library/Jupyter/kernels/<kernel>/kernel.json查看您的内核正在运行哪个python

Note: you can also programmatically install packages with:注意:您还可以通过以下方式以编程方式安装软件包:

import pip
pip.main(['install', '<package>'])

which will force it to be in the right site-packages for your kernel.这将强制它位于内核的正确site-packages中。

如果您使用的是 anaconda,则可以使用下面提到的命令安装 XGBoost:

conda install -c conda-forge xgboost

它有效,谢谢,您让我开心。

Since you are using macOS, you can use Homebrew to install xgboost :由于您使用的是 macOS,您可以使用Homebrew安装xgboost

In your terminal, run the following command:在您的终端中,运行以下命令:

brew install xgboost

See this for details.有关详细信息,请参阅内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM