No module named 'scikit' using anaconda - python

I installed scikit-learn using command conda install scikit-learn and it is available under my anaconda installation folder.
However, after running python (Python 3.5.2 |Anaconda custom (64-bit)) I get:
ImportError: No module named 'scikit'
I have the environment variables:
PYTHONHOME = C:\Users\Lejla\Anaconda3
PYTHONPATH = C:\Users\Lejla\Anaconda3\Lib
And also I have these included in my PATH:
C:\Users\Lejla\Anaconda3;C:\Users\Lejla\Anaconda3\Scripts;C:\Users\Lejla\Anaconda3\Library\bin;

This is because the scikit-learn package isn't imported via the name scikit. You should use sklearn during your import, that is:
>>> import sklearn
Take a look at their documentation while you're using it, details (among the being how to import it) are clearly shown there.

Related

Issue with Anaconda package manager - library installed, but not found in Spyder

I installed cairo using Anaconda Navigator (in case it's important, cairo is also installed in the other two environments: miniconda3 and spyder-env):
I launch Spyder from Anaconda Navigator, and try to import cairo, and get an error saying:
ModuleNotFoundError: No module named 'cairo'
Spyder seems to be using the correct python environment. If I run `conda list cairo', I get the following output:
What am I doing wrong?
I had problem similar to this with VaderSentiment analysis library. Jupyter notebook couldn't find it although it was installed. Either you can use a more stable Python version such as Python 3.7 for compatibility or you can use importlib.
conda install python=3.7
I solved it using importlib This does not answer your question "what am i doing wrong", but it solved the problem in my case. Just locate cairo.py in your Anaconda folder whatever the environment is. You can make necessary adjustments. I hope this helps if you have emergency to use that package.
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("vaderSentiment", r"C:\Users\matt\Anaconda3\envs\sentiment\Lib\site-packages\vaderSentiment\vaderSentiment.py")
foo = importlib.util.module_from_spec(spec)
sys.modules["vaderSentiment"] = foo
spec.loader.exec_module(foo)

Accessing Pattern library in Spyder

My base environment in Python 3.7. I created a new environment called Python27 (which is Python 2.7 version as I want it for Text Analytics) and is my current environment. I activated it using the command activate Python27. So, the top left corner in spyder shows as Spyder(Python 2.7)
I installed Pattern Library using pip install pattern and it got successfully installed after I resolved the C1083 error. Now I am having issues accessing it in Spyder when I type from pattern.en import suggest I get the error
ImportError: No module named pattern.en
The same issue is with spacy library. Moreover, I cant see the libraries Pattern and Spacy in conda list.
where am I going wrong?

No module named 'gensim.sklearn_api'

I try to use
from gensim.sklearn_api import W2VTransformer
and get
ImportError: No module named 'gensim.sklearn_api'
I used
import gensim
import sklearn
from sklearn.base import BaseEstimator, TransformerMixin
and get the same.
In sklearn_api.w2vmodel – Scikit learn wrapper for word2vec model I could find no advice.
How to install gensim.sklearn_api?
#tursunWali
Class names seem to have changed from v1.0.5. Try calling TFIDF and other methods by prefixing them with do_, e.g. hero.do_tfidf.
Here's a minimal example:
df['pca']=(df['text'].pipe(hero.clean).pipe(hero.do_tfidf).pipe(hero.do_pca))
You can see all the class names in the package source code.
If you're using vanilla Python, pip install -U gensim.
After importing the "texthero" library. Its shown error message:
ModuleNotFoundError: No module named 'gensim.sklearn_api'
I have tried to install 'gensim.sklearn_api', but no such module available yet.
Also created the new anaconda environment for an older version of python-like 3.6 and 3.7 but it's has shown the same error message.
Finally, I have installed the older version of texthero and its work
pip install texthero==1.0.5
The older version of texthero==1.0.5 is very much compatible with python version like 3.6, 3.7 and 3.8
For me it was the version, try: pip install "gensim==3.8.3".

Conda openpxyl install results in No module named 'openpyxl'

I installed several conda environments with different Python versions.
After activating my Python 3.5 environment I have installed openpxyl via the line given here: https://anaconda.org/anaconda/openpyxl
However, when I try to import I get
ImportError: No module named 'openpxyl'
When I type conda list I do see
openpyxl 2.4.7 py35_0 anaconda
in the list.
(code to import is just import openpyxl or from openpyxl import *)
Any suggestions? Thanks!
You can try deleting all openpyxl material then reinstall it using pip.
that's how i solved my problem at least.
Even I faced the Same issue. This might Help you. If we have given python path in the windows environment variables which is present before we installed anaconda. We can test it by using
python --version
It will give you the version if the path is already present as
Python 3.6.5
Please remove this path of python which is already mentioned.
Then give the path of the python which is is anaconda directory. Normally it will in the path
C:\Users\lenovo\Anaconda3\
Just add this path to environment variables and again check for the python version
that might give you the following result
Python 3.6.5 :: Anaconda, Inc.
then it is confirmed that you are using the python which is downloaded using anaconda package manager.
Now you use the conda modules anywhere.

import QGIS modules into Python (Anaconda)

control QGIS from within Anaconda's Spyder.
I set PAYTHONPATH to C:\Program Files\QGIS Pisa\apps\qgis\bin, but it still gives this error while import qgis.core module:
import qgis.core
ImportError: No module named qgis.core
How can I import the module?
The answer provided by j08lue works for me. But we also could do this in an Anaconda virtual environment in a specific environment-wide way. So, please try the following steps:
Create a conda environment using conda create -n conda-qgis and then activate this new environment by using conda activate conda-qgis.
Install QGIS through conda-forge in the current environment using conda install -c conda-forge qgis.
Open QGIS by running qgis.
Use the Python console in QGIS GUI, and run:
import sys
sys.path
and you might get system paths like below:
'C:/Anaconda3/envs/conda-qgis/Library/./python', 'C:/Users/Guohan/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python', 'C:/Users/Guohan/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins', 'C:/Anaconda3/envs/conda-qgis/Library/./python/plugins', 'C:\\Anaconda3\\envs\\conda-qgis\\Library\\python', 'C:\\Anaconda3\\envs\\conda-qgis\\Library\\python\\plugins', 'C:\\', 'C:\\Anaconda3\\envs\\conda-qgis\\python39.zip', 'C:\\Anaconda3\\envs\\conda-qgis\\DLLs', 'C:\\Anaconda3\\envs\\conda-qgis\\lib', 'C:\\Anaconda3\\envs\\conda-qgis\\Library\\bin', 'C:\\Anaconda3\\envs\\conda-qgis', 'C:\\Anaconda3\\envs\\conda-qgis\\lib\\site-packages', 'C:\\Anaconda3\\envs\\conda-qgis\\lib\\site-packages\\win32', 'C:\\Anaconda3\\envs\\conda-qgis\\lib\\site-packages\\win32\\lib', 'C:\\Anaconda3\\envs\\conda-qgis\\lib\\site-packages\\Pythonwin', 'C:/Users/Guohan/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python'
Copy all the paths above and get back to the command prompt and run:
conda-develop PASTEHERE -n conda-qgis
This will create a conda.pth file at the site-package directory, which stores all the environment path variables specified for this conda-qgis environment.
Finally, you should be able to use import qgis in an Anaconda environment.
The Python packages shipped with QGIS live in \path\to\QGIS\apps\Python27\Lib. So you need to add that to PYTHONPATH, rather than ...\qgis\bin.
It is best to do this on script-basis, rather than system-wide, like so:
import sys
sys.path.append("C:\Program Files\QGIS Pisa\apps\Python27\Lib")
import qgis.core
But be aware that the QGIS Python packages were likely built for a different version of Python. So things might not work smoothly.
Note: QGIS Python plugins are installed here: ~\.qgis2\python\plugins, so you might need to sys.path.append that too.

Categories