简体   繁体   English

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

[英]ImportError: No module named xgboost

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 无法获取 package 详细信息。我对 python 比较陌生,我可以轻松安装 numpy 和 8512I8531 使用的软件包此链接用于在 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 安装 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打印系统路径

['', '/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']

First you need to get control of your python environment.首先,您需要控制您的 python 环境。 Download the homebrew python by pasting these into a fresh terminal window通过将这些粘贴到新的终端窗口中来下载自制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 .安装自制软件后,使用brew install python Please check your installation with brew doctor and follow homebrew's suggestions.请使用brew doctor检查您的安装并遵循 homebrew 的建议。

Now, with a fresh terminal window, install xgboost from pip.现在,使用新的终端窗口,从 pip 安装 xgboost。 Open terminal and paste this in:打开终端并将其粘贴到:

pip install xgboost

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祝你好运

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

conda install -c conda-forge xgboost

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
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 中导入它。

Try running尝试运行

pip install xgboost

in Anaconda prompt;在 Anaconda 提示符下; it's important that you do it in Anaconda prompt so it is in same location as the Python you're using.在 Anaconda 提示符下执行此操作很重要,因此它与您使用的 Python 位于同一位置。

I tried我试过了

pip install xgboost

and

pip3 install xgboost

But it doesn't work但它不起作用

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

Finally I solved Try this in the Jupyter Notebook cell最后我解决了在 Jupyter Notebook 单元格中尝试这个

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

Results:结果:

Collecting xgboost
  Using cached xgboost-1.4.1-py3-none-win_amd64.whl (97.8 MB)
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1

在 Jupyter 的终端上写下:

conda install -c anaconda py-xgboost

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

All you need within Jupyter Notebook cell is: try running 👇👇👇在 Jupyter Notebook 单元中,您只需要:尝试运行👇👇👇

import sys
!{sys.executable} -m pip install xgboost
  1. Open the terminal打开终端
  2. Type pip install xgboost and hit enter.输入pip install xgboost并回车。

Make sure your internet connection is good.确保您的互联网连接良好。

Do not forget to crosscheck the successful installation of it in jupyter.不要忘记在 jupyter 中交叉检查它的成功安装。

Give the following commands a try.试试下面的命令。

pip install xgboost
pip install plotly

if you run如果你跑

pip install xgboots点安装 xgboots

in command line and no result, run the same command in jupyter .在命令行中没有结果,在jupyter中运行相同的命令。

for ubuntu 18 LTS, this worked for me.对于 ubuntu 18 LTS,这对我有用。 cmake is a pre-requiste to it, so if you havent you would need to install that, currently at print its version 3.10 + minimum. cmake 是它的先决条件,所以如果你还没有安装它,目前在打印它的版本为 3.10 + 最低版本。

in terminal: sudo snap install cmake --classic在终端: sudo snap install cmake --classic

in jupyter notebook(if terminal just edit it) import sys !{sys.executable} -m pip install xgboost在 jupyter notebook 中(如果终端只是编辑它) import sys !{sys.executable} -m pip install xgboost

In my case, I had multiple Python versions, and I was installing it in the wrong one.就我而言,我有多个 Python 版本,但我将其安装在错误的版本中。

pip install xgboost

installed the module on Python 3.7, but I needed to install it with Python 3.10.在 Python 3.7 上安装了模块,但我需要用 Python 3.10 安装它。 What I run was:我运行的是:

py -m pip install xgboost

which worked, since "py" is my binary for Python 3.10.这有效,因为“py”是我的 Python 3.10 二进制文件。 The suitable command if you have multiple Python versions may be different depending on which version you have.如果您有多个 Python 版本,则适用的命令可能会有所不同,具体取决于您拥有的版本。 In Ubuntu, for example, this worked for me:例如,在 Ubuntu 中,这对我有用:

python3.8 -m pip3 install xgboost

pip install xgboost or conda install xgboost pip 安装 xgboost 或 conda 安装 xgboost

Windows 10, Run Anaconda as Administrator. Windows 10、以管理员身份运行Anaconda。

  • Launch Powershell Prompt from Navigator从导航器启动 Powershell 提示
  • pip install xgboost

在此处输入图像描述

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

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