python - 导入错误 : No module named xgboost

标签 python jupyter-notebook

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

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

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

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/版本/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']

最佳答案

首先,您需要控制您的 python 环境。下载homebrew python 通过将这些粘贴到一个新的终端窗口中

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

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

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

pip install xgboost

关于python - 导入错误 : No module named xgboost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40747738/

相关文章:

python - Colab的使用限制持续多长时间?

jupyter-notebook - 使用 vim 键绑定(bind)在 JupyterLab 中退出插入模式

matplotlib - ipython notebook pylab inline - matplotlib.pyplot - 如何用滚动条显示绘图?

python - 如何从不同 django 应用程序中的相同命名模块导入所有函数?

python - 将 header 添加到 Numpy 数组

python - SQLAlchemy first() 不执行表达式

python - 将实例属性从一个模块移动到另一个模块

Python最近邻——坐标

jupyter-notebook - 启动器中的 fatal error : Unable to create process using '"'

docker - Anaconda3.sh 中的 `Failed to execute script entry_point`