I'm trying to install Scikit and run a python file that only has:
import sklearn
To check if Scikit works. This is the error I get:
Traceback (most recent call last):
File "hello-world.py", line 1, in
import sklearn
File "/Library/Python/2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone
File "/Library/Python/2.7/site-packages/sklearn/base.py", line 9, in
from scipy import sparse
ImportError: No module named scipy
I have been at this for hours now. My python version is Python 2.7.11
which -a python
gives me this:
/usr/local/bin/python
/usr/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/Users/Iliad/anaconda/bin/python
I had had Python 3.5 Installed before, but downloaded Anaconda for 2.7, but can't make sure it is set to work with that version.
Thanks!
I will start with
python --version
Just to be sure
and then in python repl. Use this
import site
site.getsitepackages()
This would give you something like :
['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
Check in all the dist-packages for scipy. My guess is that it is not there.
If you have any other "dist-packages" type of folder then you should add that to your PYTHONPATH.
Related
I'm using spyder 2 anaconda 2.3.0 on windows as a python IDE for python 2.7. I've been using this for a long time to code in python but suddenly I don't know what happened and it said I did not have biopython package installed, when I installed biopython using
conda -c install anaconda biopython
command, biopython started running however it broke pandas and numpy.
now when I import pandas I get this:
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\pandas\__init__.py", line 13, in
<module>
"extensions first.".format(module))
ImportError: C extension: hashtable not built. If you want to import pandas
from the source directory, you may need to run 'python setup.py build_ext --
inplace' to build the C extensions first.
and then when I import numpy I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
I uninstalled numpy and pandas and then installed them back using pip ... still the same. I entirely unistalled anaconda and installed it back still the same errors. I really do not know what's causing this. Any help will be truly appreciated. I've been trying to fix this for the past three days and its not working out. Thanks for your time.
Im pretty new to working with this side of python so pardon me if I'm a bit off kilter.
I am trying to incorporate PySide into Cryengine's Python 2.7.5 Integration; I used PIP to install the Site - Package to Cryengines Python Directory using the pip install PySide.whl -t CRYENGINE/Editor/Python/Lib/Site - Package command through command prompt.
Here is the script I am trying to run in the Python Shell Of CryEngine:
import sys
import site
site.ENABLE_USER_SITE
print site.USER_BASE
site.addsitedir("F:\SteamLibrary\steamapps\common\CRYENGINE\Editor\Python\Lib\site-packages\PySide")
from PySide import QtGui
app = QtGui.QApplication(sys.argv)
wid = QtGui.QWidget()
wid.resize(250, 150)
wid.setWindowTitle('Simple')
wid.show()
sys.exit(app.exec_())
I get the following error in the Python script terminal:
] from PySide import QtGui
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\PySide\__init__.py", line 41, in <module>
_setupQtDirectories()
File "C:\Python27\lib\site-packages\PySide\__init__.py", line 9, in _setupQtDirectories
from . import _utils
File "C:\Python27\lib\site-packages\PySide\_utils.py", line 31, in <module>
import ctypes
ImportError: No module named ctypes
I used pip to install the PySide wheel files. So its really weird that I am getting this error. I double checked the files that ctypes uses are there, and in the Python 2.7 installation. And all of them are there. I tested this using Python Shell, and it works great! But for some reason when I run it through CryEngine's python 2.7.5 integration even though the file path is to C:\Python27 where all of those file Ctypes files are!
I am almost sure that I am oversimplifying the problem, but I'm not sure where to start getting this problem solved. I want to get this working so I can build an integration that will work for the whole CryEngine Community. I've looked all over the place for a solution, but am really at the end of my rope here.
Any help would be greatly appreciated!!
The Problem
I'm trying to use scikit-learn on a virtual environment and I cannot get it to run.
So, for example, I go to a project folder and install NumPy, SciPy, and scikit-learn
virtualenv venv
source venv/bin/activate
pip install numpy
pip install scipy
pip install scikit-learn
Then I open python and try to import each of them.
import numpy
import scipy
import sklearn
NumPy and SciPy import fine, but when I try to import I get an error saying Library not loaded: #rpath/./libgfortran.3.dylib.
Is there something I'm missing in the installation?
Full error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/validation.py", line 16, in <module>
from ..utils.fixes import signature
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/fixes.py", line 324, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/__init__.py", line 109, in <module>
from .isolve import *
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
from . import _iterative
ImportError: dlopen(/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: #rpath/./libgfortran.3.dylib
Referenced from: /Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so
Reason: image not found
EDIT:
this was some troubleshooting to host a Heroku app using sklearn.
I would strongly recommend against using virtual environments for NumPy/SciPy/Scikit-learn and other packages which include compiled code. Virtual environments deal with pure Python dependencies reasonably well, but for compiled extensions with dependencies outside Python, they can fail in unexpected ways (as you have seen).
If you want to manage multiple environments with different versions of Python packages including compiled extensions, the best tool out there is probably conda, and in particular conda environments.
With it, you can run the following:
$ conda create -n myenv python=3.4 numpy scipy scikit-learn
$ source activate myenv
(myenv) $ python
Python 3.4.3
>>> import sklearn
and you'll be good to go.
When I upgrade Python from 2.7.9 to 2.7.10 with anaconda, I get the following error in my apache2 log and my websites don't work any more.
mod_wsgi (pid=608): Target WSGI script '/www/wsgi_scripts/django_myproject.wsgi' cannot be loaded as Python module.
Exception occurred processing WSGI script '/www/wsgi_scripts/django_myproject.wsgi'.
Traceback (most recent call last):
File "/www/wsgi_scripts/django_myproject.wsgi", line 8, in <module>
import django.core.handlers.wsgi
File "/Users/xnx/anaconda/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 6, in <module>
from io import BytesIO
File "/Users/xnx/anaconda/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Users/xnx/anaconda/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /Users/xnx/anaconda/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup
I expect this is some kind of mismatch in package library versions, but does anyone know which one?
Double check your PYTHONPATH if it's correct (you don't override it anywhere in your startup files).
Otherwise you may consider downgrading your Python from 2.7.10 to 2.7.9.
For example (as suggested in here):
conda install python=2.7.9
or when using Homebrew try:
brew switch python 2.7.9
as it could be some particular problem with 2.7.10.
Alternatively use Python 3.x instead.
My suspicion is that this is a problem with Anaconda as I've just hit the same problem. I've reported an issue here: https://github.com/conda/conda/issues/1367
update:
The conda guys have now released a fixed virtualenv package that no longer has this problem.
Hi i have installed the Scikit-learn but i keep getting error msgs when i try to import the sklearn module. it shows the following msg. anyone knows what's going on?
import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sklearn/__init__.py", line 31, in <module>
from . import __check_build
File "sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named _check_build
___________________________________________________________________________
Contents of sklearn/__check_build:
__init__.py __init__.pyc _check_build.c
_check_build.pyx setup.py setup.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
As you can see in your errors: ImportError: No module named _check_build in that directory it has .c file and it never compiled.
If you check this link you will see many parts of scikit-learn has been written in C.
So for installing this kind of packages , you need to install python-dev package in your system.
python-dev package will install many C headers like python.h.
So install python-dev package in your system and then remove and install scikit-learn package again.