问题描述
我有下面的问题(我在MAC上)
I have the problem below (I'm on a MAC)
我可以使用Terminal从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 Traceback(最近一次通话) 在 ()----> 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)已满足要求:/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages(来自xgboost)中的scipy
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匹配.您应该能够运行<base_prefix>/bin/pip install <package>
以确保它在正确的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
.
您还可以通过最有可能在~/Library/Jupyter/kernels/<kernel>/kernel.json
中查看kernel.json
来查看内核正在运行哪个python
.
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 Notebook XGboost进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!