简体   繁体   English

Xgboost在pycharm上工作,但在Jupyter NoteBook中不起作用

[英]Xgboost work on pycharm but not in Jupyter NoteBook

I've successfully installed Xgboost in windows with Pycharm Python, and it is working. 我已经使用Pycharm Python在Windows中成功安装了Xgboost,并且可以正常工作。 However, in Jupyter NoteBook, it is not working. 但是,在Jupyter NoteBook中,它不起作用。

        import xgboost as xgb
    ---> 12 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'

In Jupyter the xgboost package is at: 在Jupyter中,xgboost软件包位于:

> !pip install xgboost

Requirement already satisfied: xgboost in c:\\users\\sifangyou\\anaconda3\\lib\\site-packages\\xgboost-0.6-py3.6.egg 已满足要求:c:\\ users \\ sifangyou \\ anaconda3 \\ lib \\ site-packages \\ xgboost-0.6-py3.6.egg中的xgboost

Requirement already satisfied: numpy in c:\\users\\sifangyou\\anaconda3\\lib\\site-packages (from xgboost) 已满足要求:c:\\ users \\ sifangyou \\ anaconda3 \\ lib \\ site-packages中的numpy(来自xgboost)

Requirement already satisfied: scipy in c:\\users\\sifangyou\\anaconda3\\lib\\site-packages (from xgboost) 已经满足要求:c:\\ users \\ sifangyou \\ anaconda3 \\ lib \\ site-packages中的scipy(来自xgboost)

However, my xgboost is installed in: C:\\Users\\sifangyou\\xgboost\\python-package 但是,我的xgboost安装在:C:\\ Users \\ sifangyou \\ xgboost \\ python-package

How can I direct Jupyter to the correct xgboost package location? 如何将Jupyter定向到正确的xgboost软件包位置?

Ideally, you should install packages in the location in your PYTHONPATH (which is where python looks). 理想情况下,您应该在PYTHONPATH中的位置(即python所在的位置)安装软件包。 Usually pip does this, however its possible that jupyter, and pycharm are using different version. 通常pip会执行此操作,但是jupyter和pycharm可能使用不同的版本。 Try: 尝试:

import sys
print sys.executable

and

import os
print os.environ['PYTHONPATH'].split(os.pathsep)

in both pycharm and jupyter. 在pycharm和jupyter中。

You can then try one of two things: 然后,您可以尝试以下两种方法之一:

  1. install the package with the right version of pip: 使用正确版本的pip安装软件包:

    /path/to/python /path/to/pip install PackageName / path / to / python / path / to / pip安装PackageName

  2. dynamically hacking your python path in python: 在python中动态破解您的python路径:

:

 import sys
 sys.path.append(r"C:\Users\sifangyou\xgboost\python-package")
 import xgboost

Whether 2 works depends on what magic happens when xgboost is installed. 2是否有效取决于安装xgboost时发生了什么魔术。 (Its possible that it may not by usable without running the install steps). (有可能不运行安装步骤就无法使用)。

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

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