Force python to use a older version of a package - xgboost - python

I need to use an older version of xgboost package for compatibility issues. I am attempting to do that with pkg_resources:
import pkg_resources
pkg_resources.require("xgboost==0.90")
import xgboost
from xgboost import XGBRegressor
I get the following error:
VersionConflict: (xgboost 1.5.0 (/Users/anaconda3/lib/python3.8/site-packages), Requirement.parse('xgboost==0.90'))
When I try:
print(xgboost.__version__)
1.5.0
I have tried to pip uninstall and then pip install xgboost==0.90, but it still upgrades to 1.5.0
In my python packages directory, I have the two xgboost packages installed.
/opt/anaconda3/lib/python3.8/site-packages
xgboost
xgboost-0.90-py3.8.egg-info

Related

ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection'

I imported sklearn DecisionBoundaryDisplay via the below command in my Google Colab file.
from sklearn.inspection import DecisionBoundaryDisplay
And I'm getting the following error.
ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection'
I even installed the following packages & also tried by restarting my runtime but still I'm getting the error.
!pip install --upgrade scikit-learn
!pip install scipy
!pip3 install -U scikit-learn scipy matplotlib
How to fix this issue?
what worked for me was installing scikit learn 1.1.0, i had version 1.0.2 before and got the same error you're encountering.
pip install -U scikit-learn --user
Hope it helps.
It seems DecisionBoundaryDisplay is a new feature and it is currently in an unstable development version. To use it, you need to install the nightly build.

Pycaret cannot imported due to another import error

ImportError: cannot import name '_joblib_parallel_args' from 'sklearn.utils.fixes' (c:\users\ezgi\appdata\local\programs\python\python38\lib\site-packages\sklearn\utils\fixes.py)
To fix I update sklearn library. But, it don't work. Anyone know the reason behind it?
I update sklearn with
pip install --upgrade scikit-learn
Also, uninstall and install it with pip.
This is because one of pycaret's dependencies (imbalanced-learn) fails with the latest version of sklearn
https://github.com/scikit-learn-contrib/imbalanced-learn/issues/894
A temporary workaround until this is fixed would be to use a lower version of sklearn. If you are using pip install pycaret, then you need to use a version of sklearn < 1.0.0

cannot import name 'normalization' from 'tensorflow.python.keras.layers'

I am trying to use tensorflow_rankings, but cannot import it due to the above error. I am using tensorflow 2.8.0 and tensorflow_rankings 0.5.0, which seem to be the latest stable builds. They are what get automatically installed from
pip install tensorflow
pip install tensorflow_ranking
I am on Python 3.8.10, Windows 11.
The TF 2.8.0 docs show there is a Normalization layer in tf.keras.layers. The error seems to come from:
from tensorflow.python.keras.layers import normalization as keras_norm
in
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
Any advice?
Seems my installation of TF was corrupted. A full uninstall and reinstall fixed it.

Tensorflow Federated tutorial in Google Colab giving errors in the initialization code snippet

Here is the cell that needs to be run before starting the tutorial.
##test {"skip": true}
# tensorflow_federated_nightly also bring in tf_nightly, which
# can causes a duplicate tensorboard install, leading to errors.
!pip uninstall --yes tensorboard tb-nightly
!pip install --quiet --upgrade tensorflow_federated_nightly
!pip install --quiet --upgrade nest_asyncio
!pip install --quiet tb-nightly # or tensorboard, but not both
import nest_asyncio
nest_asyncio.apply()
It is giving out following errors:
ERROR: tensorflow 2.4.1 requires tensorboard~=2.4, which is not installed.
ERROR: tensorflow 2.4.1 has requirement gast==0.3.3, but you'll have gast 0.4.0 which is incompatible.
ERROR: tensorflow 2.4.1 has requirement grpcio~=1.32.0, but you'll have grpcio 1.34.1 which is incompatible.
ERROR: tensorflow 2.4.1 has requirement h5py~=2.10.0, but you'll have h5py 3.1.0 which is incompatible.
ERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.
Need help resolving this. I am not much familiar with libraries and classes on Tensorflow.
Even though the console says there was an error, the pip packages should have been installed correctly.
This happens because the notebooks use tensorflow-federated-nightly, which depends on an installs tf-nightly overwriting the base tensorflow install. However pip still thinks the TFF dependencies will conflict with the now overwritten TensorFlow core package.
Adding tensorflow to the !pip uninstall list may make this error go away, but the functionality of the notebook won't change.
You can import tensorflow federated like the following. It solved my error. I tried to follow Federated Learning for Image Classification and while I was trying to import tensorflow_federated it was always giving me error.
from tensorflow_federated import python as tff

Difference between scikit-learn and sklearn (now deprecated)

On OS X 10.11.6 and python 2.7.10 I need to import from sklearn manifold.
I have numpy 1.8 Orc1, scipy .13 Ob1 and scikit-learn 0.17.1 installed.
I used pip to install sklearn(0.0), but when I try to import from sklearn manifold I get the following:
Traceback (most recent call last): File "", line 1, in
File
"/Library/Python/2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone File
"/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in
from .utils.fixes import signature File
"/Library/Python/2.7/site-packages/sklearn/utils/init.py", line
10, in from .murmurhash import murmurhash3_32 File
"numpy.pxd", line 155, in init sklearn.utils.murmurhash
(sklearn/utils/murmurhash.c:5029) ValueError: numpy.dtype has the
wrong size, try recompiling.
What is the difference between scikit-learn and sklearn? Also,
I cant import scikit-learn because of a syntax error
Regarding the difference sklearn vs. scikit-learn:
The package "scikit-learn" is recommended to be installed using pip install scikit-learn but in your code imported using import sklearn.
A bit confusing, because you can also do pip install sklearn and will end up with the same scikit-learn package installed, because there is a "dummy" pypi package sklearn which will install scikit-learn for you.
From this thread:
scikit-learn is in install_requires of sklearn setup.py so you do
end-up with scikit-learn installed
So:
At the end, pip install sklearn or pip install scikit-learn ---
apart from the annoying sklearn (0.0) showed in the pip list ---
will install the latest available build from PyPI.
You might need to reinstall numpy. It doesn't seem to have been installed correctly.
sklearn is how you type the scikit-learn name in python (only the latter should be installed, the former is now deprecated).
Also, try running the standard tests in scikit-learn and check the output. You will have detailed error information there.
As a side note, do you have nosetests installed? Try: nosetests -v sklearn. You type this in bash, not in the python interpreter.
As of Dec. 1, 2022 you have to use scikit-learn in pip requirements files as pip install sklearn is now deprecated.
source: https://github.com/scikit-learn/sklearn-pypi-package
The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
rather than 'sklearn' for pip commands.
Hereafter sklearn won't available for pip install from the latest versions. So it is better to start scikit-learn
Reason for the deprecation:
sklearn package on PyPI exists to prevent malicious actors from using the sklearn package, since sklearn (the import name) and scikit-learn (the project name) are sometimes used interchangeably. scikit-learn is the actual package name and should be used with pip
Please check this link for further info
I got the same problem when uploading my project on Google Cloud. The error log said
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py"
.......ModuleNotFoundError: No module named 'sklearn'
The solution as said above worked.
Changed 'sklearn' to 'scikit-learn' in my requirements.txt

Categories

Resources