I an new to Python and am not sure how to run this code. I receive the following error:
mona$ python spectral.py
Traceback (most recent call last):
File "spectral.py", line 12, in <module>
from ..base import BaseEstimator, ClusterMixin
ValueError: Attempted relative import in non-package
>>> from ..base import BaseEstimator, ClusterMixin, TransformerMixin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
I am not sure which other files from that repository should I download or which packages should I download to be able to run this code.
Why would you want to run that script?
Install scikit-learn.
sudo pip install scikit-learn
then you can import spectral clustering in your python script:
read:
http://scikit-learn.org/stable/auto_examples/cluster/plot_lena_segmentation.html#example-cluster-plot-lena-segmentation-py
and
http://scikit-learn.org/stable/auto_examples/cluster/plot_segmentation_toy.html#example-cluster-plot-segmentation-toy-py
You have to run it as a package not just the componant.
have you already installed the sklearn package and dependancies?
if not you should check out this page and go from there to install and configure the package.
Related
I am using python39 and have imported the libraries 'numpy, scipy, matplotlib, scikit-learn and sklearn.
I am then trying to use a command with sklearn library and it is not working with the below error
from sklearn import neighbors
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
from sklearn import neighbors
File "C:\Python39\lib\site-packages\sklearn\__init__.py", line 80, in <module>
from .base import clone
ImportError: DLL load failed while importing qhull: The specified module could not be found."
I used the below commands
C:\Python39\Scripts>pip install mkl_fft-1.2.0-cp39-cp39-win_amd64.whl force
C:\Python39\Scripts>pip install mkl_random-1.2.0-cp39-cp39-win_amd64.whl force
C:\Python39\Scripts>pip install mkl_random-1.2.0-cp39-cp39-win_amd64.whl force
Then I went back to my python shell and typed
from sklearn import neighbors
It worked
I get an error when importing sklearn in python.
I am using MacBook.
>>> import sklearn
Error:
> Traceback (most recent call last): File
> "<pyshell#1>", line 1, in <module>
> import sklearn File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/__init__.py",
> line 81, in <module>
> from . import __check_build # noqa: F401 ImportError: cannot import name '__check_build' from 'sklearn'
> (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/__init__.py)
According to the pypi page for sklearn, you should be using pip install scikit-learn instead of pip install sklearn
Your requirements.txt file needs the line
scikit-learn==0.22.1
or, if you're not storing requirements for the project, then
pip install scikit-learn
on the command line.
I'm trying to distribute this code through git+pip . I was able to properly create the setup.py file for deployment but after installing the package with:
https://github.com/EKami/kaggle-data-downloader
Running this import gives me an error:
>>> from kaggle_data_downloader import KaggleDataDownloader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Ekami/Programs/anaconda/envs/tensorflow/lib/python3.6/site-packages/kaggle_data_downloader/KaggleDataDownloader.py", line 3, in <module>
import utils
ModuleNotFoundError: No module named 'utils'
But with:
>>> import kaggle_data_downloader.utils
It works. It seems KaggleDataDownloader cannot find kaggle_data_downloader.utils. I think I missed something in the setup.py file. Any idea?
Thanks.
I have tried all the import methods and upgrading the libraries but still I'm unable to get over this error. I have downloaded and installed all the nltk and corpus data programmatically and it is working in the python shell but i'm getting error.
Traceback (most recent call last):
File "spark.py", line 7, in <module>
from textblob_aptagger import PerceptronTagger
File "/usr/local/lib/python2.7/dist-packages/textblob_aptagger/__init__.py", line 8, in <module>
from textblob_aptagger.taggers import PerceptronTagger
File "/usr/local/lib/python2.7/dist-packages/textblob_aptagger/taggers.py", line 10, in <module>
from textblob.packages import nltk
ImportError: No module named packages
Here's a pastebin to my code and imports..
Same error has been posted on github here. Use this instead to install textblob:
$ pip install -U git+https://github.com/sloria/textblob-aptagger.git#dev
Also, you should change from text.blob import TextBlob as tbto from textblob...
Works for me..
I can't seem to get from sklearn.cluster import KMean to work in Python I did the whole pip install scipy/numpy and they are installed in python but I can't get the KMeans into it at the moment I have found a load of ones that are similar to my problem but I can't seem to get it working with mine.
When I do from sklearn.cluster import KMeans I just get an error that says
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
import sklearn
File "C:\Python34\lib\site-packages\sklearn\__init__.py", line 56, in <module>
from . import __check_build
ImportError: cannot import name '__check_build'
Can someone please help me I would be forever grateful!!!
This usually happens if you don't have scipy installed, so run this in your command prompt:
pip install scipy
Try this:
sudo pip install scipy
Then in Python:
import scipy