简体   繁体   中英

ImportError: No module named xgboost and package already installed

When I do:

import xgboost

I get no module named xgboost

I tried: pip install xgboost

and i get:

Requirement already satisfied: xgboost in e:\anaconda\lib\site-packages (1.0.2)
Requirement already satisfied: numpy in e:\anaconda\lib\site-packages (from xgboost) (1.18.1)
Requirement already satisfied: scipy in e:\anaconda\lib\site-packages (from xgboost) (1.4.1)

versions

Python 3.7.4
pip 20.0.2 from E:\Anaconda\lib\site-packages\pip (python 3.7)

Where python:

E:\Anaconda\python.exe
C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe

Usually this will happen because

  1. You installed the package in a virtualenv and are trying to import it outside of the env
  2. You installed the package globally and are trying to import it in a virtualenv which does not inherit the global packages
  3. Your pip is linked to a different version than the python you're using

Based on the output of the where python it seems like you probably used the pip from anaconda to install the package, but are trying to import the package in a script that you're running with the python located here C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe rather than here E:\Anaconda\python.exe

If your code with the import is in a script called test.py , for example, try running it with E:\Anaconda\python.exe test.py and see if the error still occurs

Or start a Python shell with E:\Anaconda\python.exe and then execute import xgboost in the shell and see if that works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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