Python 导入错误:没有名为 xgboost 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40747738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:57:09  来源:igfitidea点击:

ImportError: No module named xgboost

pythonjupyter-notebook

提问by miniQ

When I tried import from python terminal I get this error, although I followed all the steps to install xgboost, somehow python is unable to get the package details.I am relatively new to python, I could easily install numpy and pandas packages,I used this link for installation on MACOSX http://xgboost.readthedocs.io/en/latest/build.html

当我尝试从 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

When I did pip install xgboost, I am getting this error,

当我执行 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/ 

I am getting this on printing sys path,

我在打印系统路径时得到这个,

print sys.path

打印 sys.path

['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat -mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/lib-dynload'、'/Library/Python/2.7/site-packages'、'/System/Library/Frameworks/Python.framework/Versions/2。7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

采纳答案by kilojoules

First you need to get control of your python environment. Download the homebrewpython by pasting these into a fresh terminal window

首先你需要控制你的python环境。通过将这些粘贴到新的终端窗口中来下载自制的python

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

here you will be prompterd to enter your password. After homebrew is installed, install python with brew install python. Please check your installation with brew doctorand follow homebrew's suggestions.

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

Now, with a fresh terminal window, install xgboost from pip. Open terminaland paste this in:

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

pip install xgboost

回答by Mohamed AL ANI

I had the same issue. I tried everything but the only solution that worked for me to was to install the whl file directly from here : http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost

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

then you can do :

那么你可以这样做:

pip install yourFile.whl

On windows I managed to just double click on the whl file and install it

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

Good luck

祝你好运

回答by miniQ

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

Atleast Now I can import xgboost from terminal on macosx, I haven't been able to import it in jupyter notebook as yet.

至少现在我可以从 macosx 上的终端导入 xgboost,我还不能在 jupyter notebook 中导入它。

回答by Meng Zhao

FYI if you are using anaconda dist'n then need to do

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

conda install -c conda-forge xgboost

回答by Kim Kelly

Write this on the terminal of Jupyter:

在 Jupyter 的终端上写下这个:

conda install -c anaconda py-xgboost

回答by E.Zolduoarrati

Use conda install in Anaconda Powershell Prompt then use pip install

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

conda install -c conda-forge xgboost
pip install xgboost

回答by pfn

Try running

尝试跑步

pip install xgboost

in Anaconda prompt; it's important that you do it in Anaconda prompt so it is in same location as the Python you're using.

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

回答by user1460675

On Pycharm you can go to Pycharm > Prefernces, go to the interpreter you have and install the xgboostpackage.

在 Pycharm 上,您可以转到 Pycharm > Prefernces,转到您拥有的解释器并安装该xgboost软件包。