本文介绍了Jupyter 笔记本 xgboost 导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题(我使用的是 MAC)

I have the problem below (I'm on a MAC)

我可以使用我的终端从 python2.7 或 python3.6 导入 xgboost,但问题是我无法在我的 Jupyter 笔记本上导入它.

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.

import xgboost as xgb

ModuleNotFoundError 回溯(最近一次调用最后一次)在 ()----> 1 将 xgboost 导入为 xgb

ModuleNotFoundError Traceback (most recent call last) in ()----> 1 import xgboost as xgb

ModuleNotFoundError: 没有名为xgboost"的模块

ModuleNotFoundError: No module named 'xgboost'

虽然我写:

!pip3 install xgboost

它打印:

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

Requirement already satisfied: xgboost in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.eggRequirement 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)

请帮助我到处搜索:(

推荐答案

运行 shell 转义 !pip3 并不能保证它会安装在您正在运行的内核中.试试:

Running a shell escape !pip3 doesn't guarantee that it will install in the kernel you are running. Try:

import sys
print(sys.base_prefix)

看看这是否与您的终端 python 匹配.您应该能够运行 /bin/pip install 以确保它位于正确的 site-packages 中.

and see if this matches either of your terminal pythons. You should be able to run <base_prefix>/bin/pip install <package> to ensure it is in the right site-packages.

您还可以通过查看 kernel.json 最有可能在 ~/Library/Jupyter/kernels/ 中查看您的内核正在运行哪个 python内核>/kernel.json.

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.

注意:您还可以通过以下方式以编程方式安装软件包:

Note: you can also programmatically install packages with:

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

这将强制它在您的内核的正确site-packages 中.

which will force it to be in the right site-packages for your kernel.

这篇关于Jupyter 笔记本 xgboost 导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:35