python miniconda install sklearn but not found it - python

To install sklearn, I installed miniconda in my win10 computer, and in the Anaconda command line, I input:
(C:\Python\Miniconda3) C:\Users\apple>conda install sklearn
and it shows that install successfully
(C:\Python\Miniconda3) C:\Users\apple>conda install scikit-learn
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Python\Miniconda3:
#
scikit-learn 0.18.1 np113py36_1
There are python 2.7 and python 3.6 in my computer, and the default environment is python 3.6. However, I found that there is no sklearn in my python 3.6, when I input this order in python 3.6 command line:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64
bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sklearn
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sklearn
ModuleNotFoundError: No module named 'sklearn'
and I input the same order in python 2.7 command line, there is also:
>>> import sklearn
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import sklearn
ImportError: No module named sklearn
however in conda command line, it shows the sklearn has been installed successfully.
Could you please tell me the reason and solve it?

NOTE: It is normally inadvisable to have multiple installations of Python; use virtual environments instead if you require the use of different Python versions.
First, check which python version are you using in the command prompt.
python --verison
It should display Miniconda somewhere in your version information. If not, then it would mean that your python is executing in a different path. You would have to set the PATH variable to point to the location where the Miniconda executables are stored.
Explanation:
Usually, when a fresh installation takes place in Windows, the path for the executables is appended to the PATH variable. Using conda would use the Miniconda (or Anaconda) executables because the normal Python installation would not contain it. If you have multiple installations, your python command would point to the executables of the distribution initially installed and not Miniconda (where you have successfully installed sklearn).
You would have to go to the Environment Variables settings to change the order of the installation.

Related

Conda vtk is already installed but python shows - No module named vtk

I am trying to install vtk for python 2.7 for Windows 64 bit PC
C:\Users\Abhi>conda install vtk
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
Where as
C:\Users\Abhi>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named vtk
>>>
for pip also I've tried
C:\Users\Abhi>pip install vtk
Collecting vtk
ERROR: Could not find a version that satisfies the requirement vtk
(from versions: none) ERROR: No matching distribution found for vtk
I've tried installing from executable file https://vtk.org/download/
Any help would be appreciated
Thanks
Abhishek
It sounds like you may be installing VTK for a python environment, but then using another one when you try importing it. It's important to keep track of which python you are using when performing an install.
The way I keep things organized is to create conda environments. If I were you, I would do the following:
Create a conda environment (you can specify any version of python you want)
conda create -n myenv python=3.4
Now, you've created an environment in which you can install packages for your own python project. You can create other environments with different packages and versions for other python projects using this command. Next, make sure to activate your conda environment (you must do this every time you start a new session)
conda activate myenv
Now, after activating your environment, make sure that your environment is indeed active by running
conda info --envs
The active environment will have a * next to it. Make sure that the * is next to "myenv", not base.
After making sure you are indeed in your active environment, install all packages you need (including VTK). Here's how to install vtk:
conda install -c anaconda vtk
After you're done installing packages, you can make sure they are installed in your environment by running
conda list
Scroll down until you see your package.
Now, you should be able to run python scripts with the packages you installed. Test things out by running your import vtk line and let us know if things worked.

ModuleNotFoundError: No module named 'gensim'

My goal is to import gensim in Python 3 on Windows.
I am using Python 3.7.2 (checked by running python -V in Windows command prompt). I installed gensim by running pip install gensim. I checked the installation by running pip freeze, and saw the line gensim==3.7.3.
Then, I ran the command py to enter the interactive python mode (still in Windows command prompt). I ran the line import gensim and got the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gensim'
I also tried from gensim import test and got the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gensim'
Any suggestions? How do I install gensim on Windows with Python 3? How do I test gensim?
In Mac, open anaconda navigator, Click on 'Open Terminal option'. If you are using Windows, Run anaconda prompt as administrator and run the following command:
conda install -c conda-forge gensim
I think you have installed it using normal cmd, so it may have installed it on python2.x. Install it with anaconda prompt.
Let me know if it worked for you.
I got the same error after installing gensim in Anaconda. It worked only after I re-started the Anaconda: by exiting it, and re-opening it via the command prompt. I wanted to share this experience since someone else may meet the same issue.
To understand why this happens, you must know how Windows finds executables to run, and how the Python software is installed.
When running a command, Windows searches for an executable in the environment variable PATH. It executes the first one found.
python.exe is installed in <PYTHON_INSTALL_DIR> (e.g. C:\Python\3.7).
pip.exe and other Python tools (e.g. pylint, virtualenv, pycrust, etc.) are installed in <PYTHON_INSTALL_DIR>\Scripts.
py.exe is installed in your Windows system directory (e.g. C:\Windows).
python and pip commands use the modules found in the directory their installed in, they do not look at PATH.
So, let's say you have the following Python versions:
C:\Python\2.7
C:\Python\3.6
C:\Python\3.7
and your PATH environment contains the following directories:
C:\Python\2.7
C:\Python\3.6\Scripts
then, see the following output:
C:\>python -V
Python 2.7.16
C:\>pip -V
pip 19.1.1 from c:\python\3.6\lib\site-packages\pip (python 3.6)
C:\>py -V
Python 3.7.3
So, when running pip, it is possible that the packages are installed in another Python version then the version you'll get when running python.
To see which versions are (correctly) installed on your system, run py -0p. Example output:
C:\>py -0p
Installed Pythons found by py Launcher for Windows
-3.7-64 C:\Python\3.7-64\python.exe *
-3.7-32 C:\Python\3.7-32\python.exe
-3.6-64 C:\Python\3.6-64\python.exe
-2.7-64 C:\Python\2.7-64\python.exe
-2.7-32 C:\Python\2.7-32\python.exe
General solution (for Windows)
The best thing is not to rely on your system PATH. Use the py launcher to select the version you want. To run the pip module corresponding to the Python version you want to use, start pip as a module instead of executable.
So instead of:
pip install <package>
run:
py -3.6 -m pip install <package>
Here's My hypothesis towards your situation, since your OS is able to recognize both python and py commands in commandline, this may mean that you have two separate versions of python installed.
Since, as you mentioned that python -V shows gensim as an installed module. Try opening python interactive interpreter via command python instead of py, and import gensim module in it.
C:\Users> Python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gensim
see if that works.
P.S.
I would not recommend having two different compiler versions on a single OS as it creates a lot of commotion, and create incompatibility issues with program's made on one compiler with the other. And makes problems (like you mentioned) a lot more prevalent.
Most probably you have > 1 python installed in your machine. To install gensim (or any package) inside python command line, you can run below:
type "python" then enter
type "import subprocess" then enter
type
"subprocess.check_call(["python", '-m', 'pip', 'install', 'gensim'])"
then enter
Sample below:
>>> import subprocess
>>> subprocess.check_call(["python", '-m', 'pip', 'install', 'gensim'])
Collecting gensim
..
...
Installing collected packages: smart-open, gensim
Successfully installed gensim-3.7.3 smart-open-1.8.3
0

Astropy isn't working with Python

I've been having difficulty with Python recently, mainly since I think I had several versions and conflicts (due to Anaconda installs, canopy installs etc.). So I cleaned those out.
I reinstalled python (2.7) via brew.
I reinstalled numpy and matplotlib via pip.
I also reinstalled astropy and h5py via pip.
However, I get a clean import of numpy and matplotlib, but not of astropy and h5py:
~ > python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>> import astropy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named astropy
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named h5py
>>>
My suspicion is that your pip executable is not linked to your python executable, which means when you run pip install astropy it is installing it in the site-packages for a different python.
One way to make sure you're using the correct pip is to not use
$ pip install astropy
but instead use
$ python -m pip install astropy
If this fails, it probably means that you don't have pip installed for the python instance you're using, and you need to install it (note that for Python 2 version 2.7.9 or later, or Python 3 version 3.4 or later, pip comes bundled with Python).
If this still doesn't work, then something stranger is going on. It may be due to having $PYTHONPATH or $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH set in a way that interferes with your python imports. In this case, you could clear these variables and try again. Otherwise, I'd consider using a package bundle such as conda or canopy. It makes these kinds of installation issues much smoother.
Edit: I see now that you've used conda and canopy, and you suspect these were causing your problems. Conda and canopy, by design, both sandbox their python installations so that they shouldn't get interference from other installs in your system, unless you force such interference by setting the environment variables I mentioned above. I'd suggest reinstalling conda and wiping those environment variables from your bash/csh startup script.

Unable to install scrapy

I am trying to install scrapy and for that I have installed python 2.7 and conda(as pip was giving me errors that i couldn't solve.) after that I created a separate environment for scrapy named py2 with conda.
With this output I suppose that scrapy is installed successfully on my machine.
[py2] C:\Users\ADMIN>conda install -c https://conda.anaconda.org/scrapinghub scrapy
Fetching package metadata: ......
Solving package specifications: ...........................
# All requested packages already installed.
# packages in environment at C:\dev\Anaconda3\envs\py2:
#
scrapy 1.0.3 py27_2 scrapinghub
Now I make it sure that it is python 2.7 I executed this
[py2] C:\Users\ADMIN>py
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Which is also correct I suppose.
Now still I am unable to do this
>>> import scrapy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scrapy
which indicates that scrapy is not installed.
Environment : Windows 8 (64 bit)
I am a beginner both in python and scrapy.
There are interestingly a few hacks that are needed to run Scrapy on Windows.
You would need to install unofficial support for Windows in Python, look for PyWin32 section:
http://www.lfd.uci.edu/~gohlke/pythonlibs/ Afterwards remember to run postinstall.py -install as advised on this page.
Depending how you are setup, you might need to install C++ compiler for Python, required to run lxml:
https://www.microsoft.com/en-us/download/details.aspx?id=44266
Please look for similar questions referring to overall Python not only Scrapy e.g. error: Unable to find vcvarsall.bat Depending on how you are setup you will find hints around.
As it was all in virtual environment of conda, while installing scrapy I needed to pass the name of conda virtual environment, except that scrapy would have been installed in the root(I mean outside the environment or for the machine.)
So for py2 virtual environment, after activating this, following command will install scrapy:
conda install -n py2 -c https://conda.anaconda.org/scrapinghub scrapy
Here py2 is environment's name.
This page helped me to figure out what was happening here.
I must say python is not that easy to learn.

error message using python magic on Windows XP

I followed the instructions here...
https://github.com/ahupp/python-magic#dependencies
I ran pip install python-magic and it installed without any issues. Then I installed cygwin and added C:\cygwin\bin to my system path. When I run the python interpreter in a Windows command prompt and import magic I get this error...
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\magic.py", line 161, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
>>>
Did I miss a step?
The python-magic use libmagic,
The libmagic needs magic1.dll,
That magic1.dll is in the file package of gnuwin32.
Solution 1:
Download binaries zip or setup package of file, and adding path of bin directory of it to PATH environment variable.
Solution 2:
Also there is a new change-set in code of python-magic that fixed the problem and you don't need to file package of gnuwin32 (just add bin directory of cygwin to PATH), but currently there is not yet in magic.py while you install it with pip install python-magic or by pip install python-magic --upgrade,
So you need to install python-magic from master.
Also have a look at this post: http://www.thehackeruniversity.com/2014/02/02/obtain-python-mime-types-windows/
This guy uses Hachoir to find the mime info for binary files.

Categories