Wrongly installed module in python - 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

Related

ImportError: cannot import name 'Sonnet' from 'graphs'

The code I am trying to run is
import graph_nets as gn
and the compiler returns
ImportError: cannot import name 'Sonnet' from 'graphs'
which traces back to a line in the sonnet package that says from graphs import Sonnet, D3Graph, MatplotGraph
(I have seen many similar errors on forums and the common solution is
pip uninstall sonnet
pip install dm-sonnet
but this doesn't work for me as pip install dm-sonnet is responded with requirement already satisfied and uninstalling sonnet makes the compiler return
module 'sonnet' has no attribute '__version__'
for the same line of code I am trying to run)
The there other possible solutions?
AFAIU the correct package you need is dm-sonnet. But you have already installed sonnet. Now you need to reinstall dm-sonnet to remove remnants of sonnet and install dm-sonnet afresh.
pip uninstall -y dm-sonnet
pip install dm-sonnet
Or simply
pip install --ignore-installed dm-sonnet
To use dm-sonnet you need tensorflow. dm-sonnet doesn't automatically install tensorflow as a dependency so you need to install it yourself:
pip install tensorflow

Trouble installing hdbscan package for python : "no module named 'hdbscan'" error

I want to run an algorithm written in Python on my Ubuntu virtual machine. It needs to import the hdbscan module. I thus want to install it on my virtual machine.
Following the documentationfrom Pypi.org about this library, I simply ran :
pip install hdbscan
After a few minutes, it returned :
Succesfully built hdbscan
Installing collected packages: hdbscan
Succesfully installed hdbscan-0.8.27
However, if I run my algorithm, it still says that there's "No module named 'hdbscan'".
I tried pip uninstall hdbscan but it then returns :
WARNING : Skipping hdbscan as it is not installed.
I have tried several commands to fix this issue, like for example
sudo apt --reinstall install hdbscan
or
pip install --upgrade git+https://github.com/scikit-learn-contrib/hdbscan.git#egg=hdbscan
All I get as a result is "successfully installed" or "requirement already satisfied" but my algorithm still can't use it, "is not installed" or "unable to locate package hdbscan" alternatively as I try one command or another.
I don't know what is the cause of the problem nor how to fix it. Can anyone help me please ?
try this in your terminal
conda install -c conda-forge hdbscan
I had the same problem using Windows. I fixed it installing the various dependencies before and then hdbscan out of any environment.
I strictly recommend to run the terminal as administrator, otherwise some dependencies cannot be solved.
conda install cython
conda install numpy scipy
conda install scikit-learn
pip install hdbscan

ImportError: No module named pip after trying to upgrade pip

I am using a MacOS 10.15 and Python version 3.7.7
I wanted to upgrade pip so I ran pip install --upgrade pip, but it turns out my pip was gone (it shows ImportError: No module named pip when I want to use pip install ...)
I tried several methods like python3 -m ensurepip, but it returns
Looking in links: /var/folders/sc/f0txnv0j71l2mvss7psclh_h0000gn/T/tmpchwk90o3
Requirement already satisfied: setuptools in ./anaconda3/lib/python3.7/site-packages (49.6.0.post20200814)
Requirement already satisfied: pip in ./anaconda3/lib/python3.7/site-packages (20.2.2)
and pip install still does not work and returns the same error message.
I also tried easy_install pip and other methods but pip still does not work.
Can anyone help me with this?
Update:
Using the method from #cshelly, it works on my computer!
Try the following:
python3 -m pip --upgrade pip
The -m flag will run a library module as a script.
The pip used by python3 is called pip3. Since you're using python3, you want to do pip3 install --upgrade pip.
Since it says no module named pip, thus pip is not installed in your system
So you may try
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
to download pip directly then you can use execute it using -
python3 get-pip.py
For details you may refer - https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
PS: You may need to use sudo to make use of administrative privileges.

Scikit-Learn Version Not Updating

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.

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