ImportError: No module named xgboost - python

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

First you need to get control of your python environment. Download the homebrew python by pasting these into a fresh terminal window
/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 doctor and follow homebrew's suggestions.
Now, with a fresh terminal window, install xgboost from pip. 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
then you can do :
pip install yourFile.whl
On windows I managed to just double click on the whl file and install it
Good luck

FYI if you are using anaconda dist'n then need to do
conda install -c conda-forge xgboost

Use conda install in Anaconda Powershell Prompt then use 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.

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.

I tried
pip install xgboost
and
pip3 install xgboost
But it doesn't work
ModuleNotFoundError: No module named 'xgboost'
Finally I solved
Try this in the Jupyter Notebook cell
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

Write this on the terminal of Jupyter:
conda install -c anaconda py-xgboost

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

Give the following commands a try.
pip install xgboost
pip install plotly

All you need within Jupyter Notebook cell is:
try running
import sys
!{sys.executable} -m pip install xgboost

Open the terminal
Type pip install xgboost and hit enter.
Make sure your internet connection is good.
Do not forget to crosscheck the successful installation of it in jupyter.

for ubuntu 18 LTS, this worked for me.
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.
in terminal:
sudo snap install cmake --classic
in jupyter notebook(if terminal just edit it)
import sys
!{sys.executable} -m pip install xgboost

if you run
pip install xgboost
in command line and no result, run the same command in jupyter notebook.

In my case, I had multiple Python versions, and I was installing it in the wrong one.
pip install xgboost
installed the module on Python 3.7, but I needed to install it with Python 3.10. What I run was:
py -m pip install xgboost
which worked, since "py" is my binary for Python 3.10. The suitable command if you have multiple Python versions may be different depending on which version you have. In Ubuntu, for example, this worked for me:
python3.8 -m pip3 install xgboost

Windows 10, Run Anaconda as Administrator.
Launch Powershell Prompt from Navigator
pip install xgboost

Related

Installing a repo not in PyPI

This is my first time trying to install a repo not in PyPI. I'm not sure if I'm having a general issue or a specific issue with the package.
Repo:
https://github.com/jeslago/epftoolbox
Instructions are:
git clone https://github.com/jeslago/epftoolbox.git
cd epftoolbox
Then, simply install the library using pip:
pip install .
I've tried several approaches.
I tried adding the repo in Pycharm, as "https://github.com/jeslago/epftoolbox.git/" in the settings.
I tried using pip install from a local version of the repo
python -m pip install C:\Users\user\epftoolbox\
I tried installing in anaconda
git clone https://github.com/jeslago/epftoolbox.git
cd epftoolbox
pip install .
I get this error
Successfully built epftoolbox termcolor
ERROR: tensorflow 2.3.0 has requirement scipy==1.4.1, but you'll have scipy 1.5.2 which is incompatible.
But it finishes with "Successfully installed epftoolbox-1.0"
The issue is that I can do "import epftoolbox"
Fine. But if I try and run a script with "from epftoolbox.data import read_data"
I get the error
ModuleNotFoundError: No module named 'epftoolbox.data'
So I take it that the package didn't actually install?
I'm not sure what to try next?
I've python 3.8.5 installed 64 bit.
I've get the same issue in pycharm and idle.
Probably you need to install specific version of scipy to work with this library, try to uninstall current version and then install the correct version with this commands:
python -m uninstall scipy
python -m install -Iv scipy==1.4.1

ModuleNotFoundError: No module named 'tools.nnwrap'

I tried to install torch using:
pip install torch
Installation started, but after a few seconds I got the error:
from tools.nnwrap import generate_wrappers as generate_nn_wrappers
ModuleNotFoundError: No module named 'tools.nnwrap'
OS: Windows
Anyone who is looking for the solution refer below:
It seems command to install torch not is working as expected, instead, you can try to install PyTorch using below command.
It's working and solved my above-mentioned issue.
Run below command(for below-specified OS, package-manager, Language):
# for OS: Windows, package-manager: pip, Language: python3.6 (below command is valid for only mentioned python 3.6)
pip3 install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp36-cp36m-win_amd64.whl
pip3 install https://download.pytorch.org/whl/cu90/torchvision-0.3.0-cp36-cp36m-win_amd64.whl
For another version/type of the software (OS, package, Language) installed, the command must be generated from the below-mentioned link.
https://pytorch.org/get-started/locally/
Also, look for the Python version in your IDE(If you are using PyCharm) from the terminal using the command: python. If it returns 32bit this could happen, instead install Python 64-bit.
Follow the instructions on https://pytorch.org/get-started/locally/
Choose Package "Pip" if you want to pip install
It will give you output such as
pip3 install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp37-cp37m-win_amd64.whl
pip3 install https://download.pytorch.org/whl/cu90/torchvision-0.3.0-cp37-cp37m-win_amd64.whl
Edit: new install instructions from pytorch.org shows commands such as
pip3 install torch===1.3.1 torchvision===0.4.2 -f https://download.pytorch.org/whl/torch_stable.html
To install stable version of pytorch in windows 10 for pycharm, following command should work.
pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
For what it's worth, on Windows 10 in Anaconda, the only command which worked for me was:
pip3 install https://download.pytorch.org/whl/cu90/torch-1.0.1-cp37-cp37m-win_amd64.whl
This worked for Windows 10 using Python-3.x pip
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
For me this was fixed by checking my python version - I got this error with python 3.8, but the error went away when I downgraded to 3.7 (install instructions on the site only appear to go up to 3.7).
How I fix it in Windows 10 (x64)
31 March 2020
Install CUDA from here: https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
Version: cuda_10.2.89_441.22_win10.exe
Use official website pytorch: https://pytorch.org/get-started/locally/
This command in CMD: pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
In Anaconda3 I tried to use same website just change Package to conda:
Command in jupyter notebook: conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
And after restart it does NOT work
So I tried to use pip again in jupyter notebook: pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
And it WORKS (if no, you can try to restart kernel):
I was getting the same error, then I found that the latest pytorch install requires CUDA 10.1, and once I installed that and the matching cuDNN, then this command line succeeded:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
If you are using Anaconda (3.7) in windows then you need to install via .whl file.
Download .whl file from here:- https://download.pytorch.org/whl/torch_stable.html
then put in the working directory and install it using pip.
For my system, I have renamed anaconda's pip to pip37
pip37 install torch-1.5.1+cpu-cp37-cp37m-win_amd64.whl
pip37 install torchvision-0.6.1+cpu-cp37-cp37m-win_amd64.whl
It will install Torch 1.5 & Torchvision 0.6.1 in your anaconda environment
Try this code. It worked for me-
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
For me (Python 3.7.6 x64 on Windows 10) this line worked:
pip install torch==1.5.0 torchvision==0.6.0 -f https://download.pytorch.org/whl/torch_stable.html
To whoever that has problem with torch installation: I think instead of following any of the commands posted here, you better first check pytorch official website (https://pytorch.org/). There you can easily specify all your setup info and get the proper command for download.
for the latest version of torch use the command below.
Without CUDA Support(CPU only):
pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
With CUDA Support:
pip install torch===1.7.0+cu110 torchvision===0.8.1+cu110 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Check this link for the latest versions and get the command there itself from pytorch.
i got rid of this in next way: uninstall Python 32 bit and install 64bit.
Here you can find all versions
And here you can see pip/conda etc cmd commands to run to install torch
Had to fix this at two locations:
DEV windows 10 machine:
CD to C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts
execute: conda install pytorch
DEV Windows MSSQL Server Database Python Services
CD to C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\Scripts
execute: pip3 install torch
Try to uninstall python 3.8 32-bit and install 64-bit. it worked for me, then:
pip3 install numpy
pip3 install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
I got the same error and fixed it with:
pip install torch===1.7.0 torchvision===0.8.1 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
I'm on Windows 10, Python 3.8.6.
Alternatively:
Go to https://pytorch.org/
Scroll down to the center of the page where you'll find a section with header "INSTALL PYTORCH"
Select your preferences
Copy the command to the right of where it says: "Run this Command:"
Paste it on your termminal
Click enter (I know, sounds obvious, but it wasn't for my old self when I first started)

ImportError: No module named tensorflow - Can't install Tensorflow

I am trying to install tensorflow on mac and it's giving me this error.
ImportError: No module named tensorflow
Here is what I have done in the terminal
sudo easy_install pip
sudo easy_install --upgrade six
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl
sudo -H pip3 install --upgrade $TF_BINARY_URL
After that I try to run python and tensorflow to check my installation. It doesn't work. I have spent 3 hours on the problem.
Try installing through Anaconda...
Enter this in the Terminal
export PATH=~/anaconda2/bin:$PATH OR export PATH=~/anaconda3/bin:$PATH
And then
conda install -c https://conda.anaconda.org/jjhelmus tensorflow
This worked for me, after trying several other approaches.
I use Anaconda Navigator which includes Tensorflow. I use Spyder, it's a IDE of Anaconda Navigator similar to Matlab with variable explorer, very useful.
You have to go to the page https://www.anaconda.com/download/#macos
and download and install it. It's open source. Then open Spyder and call tensorflow lib.
It's the easiest mode to run tensorflow and virtualenvs.

Python can't find module NLTK

I followed these instructions http://www.nltk.org/install.html to install nltk module on my mac (10.6)
I have installed python 2.7, but when I open IDLE and type import nltk it gives me this error
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
ImportError: No module named nltk
The problem is the module is installed in another python version, 2.6. How can I install the package in python version 2.7? I tried some of the solutions suggested in various answers, for example I tried typing this in the terminal
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
and then installed NLTK again with the command
sudo pip install -U nltk
but I get the message: Requirement already up-to-date in /Library/Python/2.6/. So apparently the command line export PYTHONPATH didn't do anything (it still tries to install the package in 2.6) OR (more likely) I didn't understand the meaning/functioning of that command line. What am I doing wrong?
On OS X you could have multiple installation of Python, so investigate it first:
$ which python python2 python3
/usr/bin/python
/usr/local/bin/python3
$ which pip pip2 pip3
/usr/local/bin/pip
/usr/local/bin/pip2
/usr/local/bin/pip3
All within /usr/bin are built-in and all other in /usr/local/bin are external installed by Homebrew or some other package manager.
If you're using pip or pip3 from /usr/local, then you've to use the same Python instance, otherwise they're different instances.
Just install it via pip:
pip install nltk
or for Python 3:
pip3 install nltk
then run the right Python instance from /usr/local/bin or update your PATH system variable.
Make sure you install the actual Python for Mac, not the one built into the console. Then, install pip by executing this script. Then skip to part 3 of the instructions and go from there.
Try this
pip install --user -U nltk
On my mac I had two different versions of Python 3 installed: Python 3.6 and Python 3.7. I had installed nltk having Python 3.7 in my $PATH:
$ pip3 install nltk
$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
But nltk was missing for Python 3.6. Solution: install nltk also for version 3.6.
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ pip3 install nltk
Collecting nltk
Using cached https://files.pythonhosted.org/packages/6f/ed/9c755d357d33bc1931e157f537721efb5b88d2c583fe593cc09603076cc3/nltk-3.4.zip
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nltk) (1.12.0)
Collecting singledispatch (from nltk)
Using cached https://files.pythonhosted.org/packages/c5/10/369f50bcd4621b263927b0a1519987a04383d4a98fb10438042ad410cf88/singledispatch-3.4.0.3-py2.py3-none-any.whl
Installing collected packages: singledispatch, nltk
Running setup.py install for nltk ... done
Successfully installed nltk-3.4 singledispatch-3.4.0.3
I would use a virtualenv, but if you really want to use it from the terminal, I'd recommend adding your export statement to ~/.bashrc
Just restart Jupyter Notebook or anything you are using after installing...
It works...
In my case, the following command worked for me. Try this!!
py -3 -m pip install nltk
I had a similar issue an an Intel MacBook.
Fixed with
Make sure the python bin directory in the path
mine is /Users/<user>/Library/Python/3.9/bin
Restart the computer
NOTE that just restarting the terminal did NOT help

If I install python scikit-learn through pip, I get latest version, but python cannot import module

System: Ubuntu 12.04 (precise)
If I install scikit-learn through
sudo apt-get install python-sklearn
I can import sklearn in python but get version 0.10, which I do not want
If I install scikit-learn through
sudo pip install -U scikit-learn
I can see the scikit_learn-0.14.1-py2.7.egg-info under /usr/local/lib/python2.7/dist-packages/
but I don't know how to get python to import the correct version. Setting PYTHONPATH to /usr/local/lib/python2.7/dist-packages/ did not help.
How do I get python to load the modules from where pip puts them, not where apt-get install puts them?
You can set the site dir in your code.
import site
site.addsitedir('/usr/local/lib/python2.7/dist-packages')
It might be the case that you have several versions of python installed and the pip command in your PATH is not matching the python command in your path. You can check with:
which python
which pip
cat `which pip`

Categories

Resources