Scikit-Learn Version Not Updating - python

I am trying to update scikit-learn library via pip, yet I have not succeded due to error occurences.
I have initially updated it using the command below:
sudo pip install -U scikit-learn
Though, it says that:
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/dist-packages
Which to my concern means that it is the latest version 0.19.0
But when I check the version directly in Python interpreter, it returns 0.16.1:
>>> import sklearn
>>> print sklearn.__version__
0.16.1
How can I update to the latest version?

By prepending sudo in the pip call, you are referring to the system's python instead of a virtualenv one.
If you are within a virtualenv, simply do pip install -U scikit-learn (i.e. drop the sudo).
EDIT:
OP installed sklearn with apt, sudo apt remove --purge python-sklearn and reinstall sklearn with pip solved it.

Related

I'm unable to install some specific libraries via pip install

I've been trying to install the gym library via pip install gym
I get the following error
WARNING: Discarding https://files.pythonhosted.org/packages/87/86/3f5467531428b6ce6f3c12d3121b4304d2ea1536a50775a4df036add37b8/gym-0.23.1.tar.gz#sha256=d0f9b9da34edbdace421c9442fc9205d03b8d15d0fb451053c766cde706d40e0 (from https://pypi.org/simple/gym/) (requires-python:>=3.7). Requested gym==0.23.1 from https://files.pythonhosted.org/packages/87/86/3f5467531428b6ce6f3c12d3121b4304d2ea1536a50775a4df036add37b8/gym-0.23.1.tar.gz#sha256=d0f9b9da34edbdace421c9442fc9205d03b8d15d0fb451053c766cde706d40e0 has inconsistent version: filename has '0.23.1', but metadata has '0.23.1'
ERROR: Could not find a version that satisfies the requirement gym==0.23.1
ERROR: No matching distribution found for gym==0.23.1
pip then defaults to trying to install previous versions 0.23.0, 0.22.0 and so on.
I get the following warning for all versions and none installs.
request gym from <link> has inconsistent version: filename has '0.9.0', but metadata has '0.9.0'
After some Googling for similar errors, I tried updating pip python3 -m pip install --upgrade pip setuptools wheel
but I get the same problem with version mismatch, and it tries to install old versions of pip and fails.
I'm on Python 3.10.4 and pip 21.0 under Arch Linux.
edit: The same problem happens to any package I try to install with pip.
I found a solution here.
The problem seems to be caused by the python-pip package under Arch Linux.
One possible way to fix it:
sudo pacman -Rncs python-pip
python -m ensurepip
If you cannot figure out pip use git
git clone https://github.com/openai/gym
cd gym
pip install -e .
Try to install with an upgrade option to install the latest without cache since looks that the latest version is stable:
pip install gym -U --no-cache-dir
-U, --upgrade Upgrade all packages to the newest available version
--no-cache-dir Disable the cache
If this won't help you can try to install using legacy version resolver (as per https://github.com/pypa/pip/issues/9203):
pip install gym -U --no-cache-dir --use-deprecated=legacy-resolver

install scikit-learn on python

I tried to use the following two commands to install scikit-learn on Mac OS:
pip3 install -u scikit-learn
pip3 install scikit-learn
I did not know "-u" stands for upgrade and used the -u command first. Then when I used the second command, I got the following error message:
Collecting scikit-learn
Using cached scikit-learn-0.18.1.tar.gz
Installing collected packages: scikit-learn
Running setup.py install for scikit-learn … error
What should I do? thanks.
The -u option you are talking about is actually -U which means as specified in manual
Upgrade all specified packages to the newest available version. This process is recursive regardless of whether a dependency is already satisfied.
Now to install scikit-learn first make sure you have all the dependencies already installed in order to install this library which are
Python (>= 2.6 or >= 3.3)
NumPy (>= 1.6.1)
SciPy (>= 0.9)
as mentioned on their site.
Alternatively you might wanna try Anaconda version of python which comes with all these modules/libraries pre-installed.
Thanks all for the helpful answers. I was able to solve the problem and here is how. First I installed Xcode. I should have clarified that I was trying to install it on a mac. Though I still don't know why I need Xcode, it worked. Second I used the sudo statements: sudo pip3 install -u scikit-learn.

How to upgrade scikit-learn package in anaconda

I am trying to upgrade package of scikit-learn from 0.16 to 0.17. For that I am trying to use binaries from this website: http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn. I have Windows 7 x64 bit. I downloaded the relevant package locally and gave following commands and got Requirement already up-to-date:
C:\Users\skumar>pip install --upgrade --use-wheel --no-index --find-links=../../
SOURCE/APPS scikit-learn
Ignoring indexes: https://pypi.python.org/simple
Requirement already up-to-date: scikit-learn in c:\anaconda3\lib\site-packages
Then I tried to upgrade it from remote site and got similar result:
C:\Users\skumar>pip install --upgrade --use-wheel --no-index --trusted-host www.
lfd.uci.edu --find-links=http://www.lfd.uci.edu/~gohlke/pythonlibs/ scikit-learn
Ignoring indexes: https://pypi.python.org/simple
Requirement already up-to-date: scikit-learn in c:\anaconda3\lib\site-packages
On Remote site there are two versions i.e., 0.16 & 0.17. Is there a way to specify version in command? Or how do you install/upgrade wheel file?
Anaconda comes with the conda package manager which is designed to handle these kinds of upgrades. Start by updating conda itself to get the most recent package lists:
conda update conda
And then install the version of scikit-learn you want
conda install scikit-learn=0.17
All necessary dependencies will be upgraded as well. If you have trouble with conda on Windows, there are some relevant FAQ here: http://docs.continuum.io/anaconda/faq
Following Worked for me for scikit-learn on Anaconda-Jupyter Notebook.
Upgrading my scikit-learn from 0.19.1 to 0.19.2 in anaconda installed on Ubuntu on Google VM instance:
Run the following commands in the terminal:
First, check existing available packages with versions by using:
conda list
It will show different packages and their installed versions in the output. Here check for scikit-learn. e.g. for me, the output was:
scikit-learn 0.19.1 py36hedc7406_0
Now I want to Upgrade to 0.19.2 July 2018 release i.e. latest available version.
conda config --append channels conda-forge
conda install scikit-learn=0.19.2
As you are trying to upgrade to 0.17 version try the following command:
conda install scikit-learn=0.17
Now check the required version of the scikit-learn is installed correctly or not by using:
conda list
For me the Output was:
scikit-learn 0.19.2 py36_blas_openblasha84fab4_201 [blas_openblas] conda-forge
Note: Don't use pip command if you are using Anaconda or Miniconda
I tried following commands:
!conda update conda
!pip install -U scikit-learn
It will install the required packages also will show in the conda list but if you try to import that package it will not work.
On the website http://scikit-learn.org/stable/install.html it is mentioned as:
Warning To upgrade or uninstall scikit-learn installed with Anaconda or conda you should not use the pip.
So to upgrade scikit-learn package, you have to follow below process
Step-1: Open your terminal(Ctrl+Alt+t)
Step-2: Now for checking currently installed packages along with the
versions installed on your
conda environment by typing conda list
Step-3: Now for upgrade type below command
conda update scikit-learn
Hope it helps!!
I would suggest using conda. Conda is an anconda specific package manager. If you want to know more about conda, read the conda docs.
Using conda in the command line, the command below would install scipy 0.17.
conda install scipy=0.17.0
Updating a Specific Library - scikit-learn:
Anaconda (conda):
conda install scikit-learn
Pip Installs Packages (pip):
pip install --upgrade scikit-learn
Verify Update:
conda list scikit-learn
It should now display the current (and desired) version of the scikit-learn library.
For me personally, I tried using the conda command to update the scikit-learn library and it acted as if it were installing the latest version to then later discover (with an execution of the conda list scikit-learn command) that it was the same version as previously and never updated (or recognized the update?). When I used the pip command, it worked like a charm and correctly updated the scikit-learn library to the latest version!
Hope this helps!
More in-depth details of latest version can be found here (be mindful this applies to the scikit-learn library version of 0.22):
Release Highlights for scikit-learn 0.22
I made it work to update to 0.24.1, on Windows 10 64bits, so I share the way I did it with the GUI:
launch Anaconda3 gui
on the left menu, click "environments"
next to "base (root)", click on the green arrow/triangle
select "Open Terminal"
type the command line:
conda install scikit-learn==0.24.1
It worked without error.
If you are using Jupyter in anaconda, after conda update scikit-learn in terminal, close anaconda and restart, otherwise the error will occur again.

Wrongly installed module in python

I tried to install sci-kit learn module in python on ubuntu. As explained in their tutorial, I did:
pip install --user --install-option="--prefix=" -U scikit-learn
But when, in python console, I try
import sklearn
I get:
ImportError: No module named sklearn
Moreover, if I do
pip list
sklearn does not appear in the list.
And if I try:
sudo pip install scikit-learn
I get:
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in ./.local/lib/python2.7/site-packages
It's probably caused by the folder ~/.local/lib not appearing in your sys.path. You can update the sys.path in a couple of ways. Either set the PYTHONPATH environment variable before running the console, or just append to the sys.path array.
You could uninstall the module and then reinstall as root:
pip uninstall scikit-learn ; sudo pip install scikit-learn
You can also just delete the ~/.local/lib folder and reinstall the package.
I had the same problem, but when I used sudo pip uninstall scikit-learn or sudo pip install -U scikit-learn I'm dealing with the following error:
Cannot uninstall 'scikit-learn'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
My problem solved by the following line:
sudo pip install --ignore-installed scikit-learn==0.18

Installing specific package version with pip

I am trying to install version 1.2.2 of MySQL_python, using a fresh virtualenv created with the --no-site-packages option. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I have tried:
pip install MySQL_python==1.2.2
However, when installed, it still shows MySQL_python-1.2.3-py2.6.egg-info in the site packages. Is this a problem specific to this package, or am I doing something wrong?
TL;DR:
Update as of 2022-12-28:
pip install --force-reinstall -v
For example: pip install --force-reinstall -v "MySQL_python==1.2.2"
What these options mean:
--force-reinstall is an option to reinstall all packages even if they are already up-to-date.
-v is for verbose. You can combine for even more verbosity (i.e. -vv) up to 3 times (e.g. --force-reinstall -vvv).
Thanks to #Peter for highlighting this (and it seems that the context of the question has broadened given the time when the question was first asked!), the documentation for Python discusses a caveat with using -I, in that it can break your installation if it was installed with a different package manager or if if your package is/was a different version.
Original answer:
pip install -Iv (i.e. pip install -Iv MySQL_python==1.2.2)
What these options mean:
-I stands for --ignore-installed which will ignore the installed packages, overwriting them.
-v is for verbose. You can combine for even more verbosity (i.e. -vv) up to 3 times (e.g. -Ivvv).
For more information, see pip install --help
First, I see two issues with what you're trying to do. Since you already have an installed version, you should either uninstall the current existing driver or use pip install -I MySQL_python==1.2.2
However, you'll soon find out that this doesn't work. If you look at pip's installation log, or if you do a pip install -Iv MySQL_python==1.2.2 you'll find that the PyPI URL link does not work for MySQL_python v1.2.2. You can verify this here: http://pypi.python.org/pypi/MySQL-python/1.2.2
The download link 404s and the fallback URL links are re-directing infinitely due to sourceforge.net's recent upgrade and PyPI's stale URL.
So to properly install the driver, you can follow these steps:
pip uninstall MySQL_python
pip install -Iv http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz/download
You can even use a version range with pip install command. Something like this:
pip install 'stevedore>=1.3.0,<1.4.0'
And if the package is already installed and you want to downgrade it add --force-reinstall like this:
pip install 'stevedore>=1.3.0,<1.4.0' --force-reinstall
One way, as suggested in this post, is to mention version in pip as:
pip install -Iv MySQL_python==1.2.2
i.e. Use == and mention the version number to install only that version. -I, --ignore-installed ignores already installed packages.
To install a specific python package version whether it is the first time, an upgrade or a downgrade use:
pip install --force-reinstall MySQL_python==1.2.4
MySQL_python version 1.2.2 is not available so I used a different version. To view all available package versions from an index exclude the version:
pip install MySQL_python==
I believe that if you already have a package it installed, pip will not overwrite it with another version. Use -I to ignore previous versions.
Sometimes, the previously installed version is cached.
~$ pip install pillow==5.2.0
It returns the followings:
Requirement already satisfied: pillow==5.2.0 in /home/ubuntu/anaconda3/lib/python3.6/site-packages (5.2.0)
We can use --no-cache-dir together with -I to overwrite this
~$ pip install --no-cache-dir -I pillow==5.2.0
Since this appeared to be a breaking change introduced in version 10 of pip, I downgraded to a compatible version:
pip install 'pip<10'
This command tells pip to install a version of the module lower than version 10. Do this in a virutalenv so you don't screw up your site installation of Python.
This below command worked for me
Python version - 2.7
package - python-jenkins
command - $ pip install 'python-jenkins>=1.1.1'
I recently ran into an issue when using pip's -I flag that I wanted to document somewhere:
-I will not uninstall the existing package before proceeding; it will just install it on top of the old one. This means that any files that should be deleted between versions will instead be left in place. This can cause weird behavior if those files share names with other installed modules.
For example, let's say there's a package named package. In one of packages files, they use import datetime. Now, in package#2.0.0, this points to the standard library datetime module, but in package#3.0.0, they added a local datetime.py as a replacement for the standard library version (for whatever reason).
Now lets say I run pip install package==3.0.0, but then later realize that I actually wanted version 2.0.0. If I now run pip install -I package==2.0.0, the old datetime.py file will not be removed, so any calls to import datetime will import the wrong module.
In my case, this manifested with strange syntax errors because the newer version of the package added a file that was only compatible with Python 3, and when I downgraded package versions to support Python 2, I continued importing the Python-3-only module.
Based on this, I would argue that uninstalling the old package is always preferable to using -I when updating installed package versions.
There are 2 ways you may install any package with version:-
A). pip install -Iv package-name == version
B). pip install -v package-name == version
For A
Here, if you're using -I option while installing(when you don't know if the package is already installed) (like 'pip install -Iv pyreadline == 2.* 'or something), you would be installing a new separate package with the same existing package having some different version.
For B
At first, you may want to check for no broken requirements.
pip check
2.and then see what's already installed by
pip list
3.if the list of the packages contain any package that you wish to install with specific version then the better option is to uninstall the package of this version first, by
pip uninstall package-name
4.And now you can go ahead to reinstall the same package with a specific version, by
pip install -v package-name==version
e.g. pip install -v pyreadline == 2.*
If you want to update to latest version and you don't know what is the latest version you can type.
pip install MySQL_python --upgrade
This will update the MySQL_python for latest version available, you can use for any other package version.
dependency packaging has had a new release, wherein it has dropped LegacyVersion from its codebase
The quick solution might be pin packaging==21.3

Categories

Resources