ImportError: No module named xgboost and package already installed - python

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
You installed the package in a virtualenv and are trying to import it outside of the env
You installed the package globally and are trying to import it in a virtualenv which does not inherit the global packages
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

Related

Getting : No module named 'clr' after changing python version

I had python 3.7.7 32bit installed on my laptop. I installed pip and pythonnet.
I have this line of code in my python project which is executing fine.
import sys, os, clr, time
from pathlib import Path
Now I have installed python 3.7.7 64bit version on my laptop. Before running the application, I changed the current python environment to point to 64bit. Upon changing the env, I'm getting the error :
No module named 'clr'
Do I have install pythonnet again for 64bit. If yes, how to do it again? Because when I try to install again it says
Requirement already satisfied: pythonnet in
c:\users\XXXXXX\appdata\local\programs\python\python37-32\lib\site-packages
(2.5.2) Requirement already satisfied: pycparser in
c:\users\XXXXXX\appdata\local\programs\python\python37-32\lib\site-packages
(from pythonnet) (2.21)
It is referring to python37-32 still. How do I target it to python37 (64bit).
I have stumbled into this issue a lot with my classmates in programming classes. The problem is that different programs point to different versions of Python. Assuming you're using VS Code, you are able to change which Python version to use, by the "Python: Select Interpreter" command.
Assuming you're using the terminal, you can change which Python version to use when you type "python", by changing your PATH environments.

Unable to import psutil in python3 with cygwin [ImportError: no os specific module found]

I've been trying to import the psutil module from cygwin (as a Linux alternative for Windows 7). The installation worked, though.
When re-installed, it showed:
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
But when imported, it gave:
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/psutil/__init__.py", line 61, in <module>
raise ImportError('no os specific module found')
ImportError: no os specific module found
I tried a couple of things:
Upgrading the pip and psutil itself, using these commands:
python3 -m pip install --upgrade pip
pip3 install --upgrade psutil
so the current version:
Requirement already satisfied: pip in /usr/local/lib/python3.8/site-packages (21.2.4)
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
Made sure that packages are installed only in the python 3.8.10 version (I have multiple versions of python installed, so I figured the inconsistency of versions may be causing the problem. But still, it didn't help).
Though, what I've done so far is just making sure I'd type an extra "3" after each python-related command.
I'm still new to cygwin and python, any help would be very much appreciated, thanks!
I may be wrong here, but I did some digging, and it looks like they have been trying add cygwin support for psutil since 2010, see github page for psutil issue #82. Looks like there is no support for now.

ModuleNotFoundError: No module named 'bs4' [sublime text 3]

Basically I am trying to run some simple code in sublime text 3 but when I try to run it it gives me the following error:
File "/Users/ingodavila/Desktop/My Programming/scrape.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I have tried installing it with pip3 and easy_install but it does not work. Whenever I try installing it it in terminal it keeps showing:
Requirement already satisfied: bs4 in ./opt/anaconda3/lib/python3.8/site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in ./opt/anaconda3/lib/python3.8/site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in ./opt/anaconda3/lib/python3.8/site-packages (from beautifulsoup4->bs4)
I tried running it in a jupyter notebook and it works but for sublime it keeps showing that 'nomodulefound' error. What can I do to solve this?
Are you running the code inside a virtual environment?
If you are, try this method:
activate the env
install the module (inside the virtualenv)
run the code.
If the above doesn't work, try:
conda install bs4
It is probably because your Sublime text interpreter is different than your global one. I would recommend you using virtual environment instead of just installing modules globally. Check this one out on how to create venv. Once you set up your virtualenv and active it, you can just install packages and use them without any problem.

No module named 'numpy' but Requirement already satisfied: numpy

When I want to execute my script I got the error: ModuleNotFoundError: No module named 'numpy'. But the module is already installed as said me the answer to the install command:
C:\WINDOWS\system32>pip install numpy
Requirement already satisfied: numpy in c:\users\simeo\anaconda3\envs\tensorflow1\lib\site-packages (1.17.2)
I'm quite new with Python, so I don't understand why it's not working and what could be the problem.
I'm using Windows 10 (64 bits). I installed Python 3.7
Thanks in advance!
For Windows try either two of these methods in cmd:
pip3 install numpy
pip3 install -U numpy
directly download latest version from sourceforge.net
If you are using pycharm, it can not install numpy from interpreter settings. After one of above method works, try installing numpy in pycharm again through interpreter settings.
You need to upgrade your Numpy library. Your current Keras version is not compatible with your Numpy module. You can use the below-given command to upgrade Numpy.pip install -U numpy
Try adding this to your code, above everything else:
import numpy

ModuleNotFoundError: No module named 'spatial'

I've been faced to Module Not Found Error in a script which all it's requirements has been installed. I'm trying to import spatial library:
import spatial
This library is located here:
C:\Users\ASUS\AppData\Local\Programs\Python\Python37\Lib\site-packages\scipy\spatial
I checked installed packages through pip list and it was okay. I tried to install spatial-lib in Pycharm project environment but it couldn't be done:
Could not find a version that satisfies the requirement spatial-lib (from versions: )
No matching distribution found for spatial-lib
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
It's nonesence, because my pip is up-to-date. Maybe good to say, importing scipy has such probelms too.
It looks like spatial is a sub-package of scipy. Therefore, to import spatial, you should use the following:
from scipy import spatial

Categories