Could not import sklearn as well as scikit-learn in my pycharm IDE, almost I have worked with them for a year now. Could not fix the issue. Tried uninstalling and installing sklearn learn again and it install a version 0.0 :(
In all my other virtual environments also I could see sklearn as 0.0 version only (without updating it from anywhere!)
And I could see scikit-learn installed, but could not import as import scikitlearn
Any help would be appreciated!
Was using an older version of PyCharm since there was an issue in the debugging in the latest version. But when I tried the latest version the packages were able to be imported! Not sure what went wrong :/
Related
I am Windows and using python through jupyternotebook.
python 3.9.7, windows 64 bit,
I want to import geopandas, so I used the code conda install --channel conda-forge geopandas. It seemed work at first because I could successfully import geopandas without error, but when I want to run the following code, an import error appears.
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
world.columns
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: DLL load failed while importing ogrext
I saw other people asked the same questions, but none of their solutions worked. At first, I saw someone said nstalling geopandas by condas might installed wrong version of fiona and gdal. So I tried to update by conda update conda, and conda update -n base conda-package-handling and conda update --all. However, these code didn't work. Later, I directly installed the .whl file from python library: Fiona-1.8.20-cp39-cp39-win_amd64.whl and GDAL-3.4.1-cp39-cp39-win_amd64.whl, and use pip to install them. But the error still appeared.
I really have no idea how to deal with such issue, is it because the version of fiona and gdal was not consistent? Please give me some suggestions, thanks ahead!
I have solved this problem by creating a new environment followed this article: https://medium.com/analytics-vidhya/fastest-way-to-install-geopandas-in-jupyter-notebook-on-windows-8f734e11fa2b
This is the fast way to solve this problem.
I have been trying to utilise mutual_info_regression method from sklearn, I have updated sklearn to latest build which is 0.24.1 and when I checked the source code inside my conda env path there is folder and files for feature_selection.mutual_info_regression, but when I try to import it in my Jupiter notebook it throws this error ImportError: cannot import name 'mutual_info_regression' from 'sklearn.model_selection' (/opt/anaconda3/envs/<my_env>/lib/python3.8/site-packages/sklearn/model_selection/__init__.py)
I tried restarting kernel as well, but it is still not working, has anyone else faced this issue? Im using macOS 11.2.1 and conda 4.8.3 with Python3
Thanks
I found the solution,
I just had to restart my terminal and then it started working for some reason.
I hope this helps anyone facing such problem in future
Thanks SO!
import sklearn
print(sklearn.__version__)
Check your sklearn version sklearn.model_selection is only available for version 0.18.1
Then try this in Jupyter Notebook cell
from sklearn.feature_selection import mutual_info_regression
If any of the above doesn't work try these three steps
1- pip uninstall sklearn
2- pip uninstall scikit-learn
3- pip install sklearn
I am experimenting with some code that still uses the old sklearn module from sklearn.cross_validation import KFold. Instead I should use sklearn.model_selection, however this causes other errors inside the code.
I know version 0.17 of sklearn still has the depricated cross_validation. However I cannot install this using pip as it doesnt find that version.
I am using a virtuel envirement with python 3.3, how could I still use the older library?
import pysal as ps
I'm tring to import pysal but I get the following:
cannot import name 'haversine_distances' from 'sklearn.metrics.pairwise'
So I tried:
from sklearn.metrics.pairwise import haversine_distances
and I get the same message.
Any suggestions?
The problem may be that your version of scikit-learn is out of date. Try uninstalling and reinstalling scikit-learn from the terminal like so:
conda uninstall scikit-learn
Confirm, and wait for the packages to be uninstalled. Then, do conda install scikit-learn and conda install pysal to reinstall the packages. You'll also need to reinstall any other packages that rely on scikit-learn as well.
I had the same issue, and this fixed the problem for me.
About scikit learn's Haversine, you have to update your scikit-learn to latest version. If you check on scikitlearn website you will find out that this module is implemented in version 0.22.1:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.haversine_distances.html
I am trying to use Xgboost in GCP datalab. I have already installed sklearn but I keep getting the error :
" XGBoostError: sklearn needs to be installed in order to use this
module"
Below is the code I used:
import sklearn
!pip3 install xgboost
from xgboost.sklearn import XGBClassifier
model = XGBClassifier()
I have tried using Python v 2.7 instead, but no luck...does anyone know how to solve this issue in GCP Datalab?
I also faced the same issue, on python 3.7 32bit on ipython.
Solution: Uninstall the xgboost package by pip uninstall xgboost on terminal/cmd. Cross-check on the your console if you cannot import it. Now again install xgboost pip install xgboost or pip install xgboost-0.81-cp37-cp37m-win32.whl, given that you have already installed sklearn, it will work on newer console session.
xgboost wheel Link: https://pypi.org/project/xgboost/#files
I got the same error with a more complicated project, after releasing a new version suddenly it failed.
luckily in my case, I had docker images for each version, and was able to use pip freeze to see what changed.
In both version I used xgboost==0.81
In the version that worked I had scikit-learn==0.21.3 and in the new version it was scikit-learn==0.22
surprisingly enough, that's now what caused the issue. I've tried to uninstall xgboost like it was suggested here and reverted scikit-learn to the version is was originally on, and still no luck.
what did cause the issue was an update of numpy from 1.17.4 to 1.18.0.
reverting it solved it for me (not sure why)
this was python 3.6 on ubuntu
For me un- then re-installing first sklearn and then xgboost did the trick