1

Though there is another question on the same issue, the solution stated there does not work for me. Hence this is not a duplicate or re-post. And I am posting my issue and implementation specifics here.

I am currently working on PyCharm on a simple ML prediction task where I'd like to use xgboost. I have performed the following so far.

  • cd into the virtual environment folder

    $ cd My_Project

  • Activate the venv

    source myproject/bin/activate

  • pip install xgboost

    $ sudo pip install xgboost

  • Upgrade installation

    $ sudo pip install --upgrade xgboost

I also added the xgboost module to the project interpreter in pycharm with Python 3.6.

enter image description here

The python file that I'm trying to run has the following imports.

from numpy import loadtxt
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split

But as I run the script, I get this error.

from xgboost import XGBClassifier ImportError: No module named 'xgboost'

Specifications

  • Ubuntu 16.04
  • PyCharm
  • Python 3.6
  • File name : classifxg.py (NOT xgboost.py - which is said to cause this No module error according to the other question on stackoverflow)

Any help in this regard will be much appreciated.

Nayantara Jeyaraj
  • 2,624
  • 7
  • 34
  • 63

1 Answers1

0

I had the same problem, but found out my file was also named xgboost.py, so it was trying to import the Classifier from my own file not the dependency.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46