Failed to import Sklearn - python

I am trying to build a recommender system with Python. However, I can't proceed since I get an import error of Sklearn everytime.
I get this error:
"ImportError: DLL load failed: Can't find module."
How do i fix this? (The last sentence in the error is in Dutch btw)
A screenshot of my error is below.
By the way: I get the same import error for Seaborn

Windows 10 + Visual Studio Code - "CMD + SHIFT + P" from within visual studio code and search for "Select Interpreter" clicking on this will show a list of available python interpreters and versions installed on your system that are detected by visual studio code and your currently selected environment. (Visual Studio Code usually incorrectly defaults to 32 bit interpreter)
Ensure you have the correct python environment (where you have the required libraries & "packages" installed)
This should fix your import issue if you have the libraries installed. Use the appropriate cmd line tool to install packages. If you are using Anaconda - use Conda Install or use pip etc...

Scikit-learn uses numpy and scipy. Those modules are using C and Fortran code that needs to be compiled. Nonetheless, Windows cannot compile them right away.
I would recommend you to download Anaconda and install scikit-learn like this. (You may need to add conda to path)
Another method is to download precompiled binary from this page. Then run:
pip uninstall scikit-learn
pip install <numpy-wheel>
pip install <scipy-wheel>
pip install <scikit-wheel>

Related

No module found error for a downloaded package (sksparse.cholmod) and how to download a package from the internet to conda

I need to use the sksparse.chomod package however my pycharm does not let me install it as it can't seem to find it.
I found the sksparse package on github and downloaded it but I do not know how to add a package downloaded from the internet into a conda environment. So, my first question would be can you download a package from github and add it to your conda environment, and how do you do this?
As I did not know how to do the above I instead saved the package within my project and thought I could simply import sksparse.cholmod. However, the line in my code that says import sksparse.cholmod as sks has no errors with it, so I assumed that meant this was ok, but when I try to run my file I get this error:
import sksparse.cholmod as sks
ModuleNotFoundError: No module named 'sksparse.cholmod'
If I have downloaded the package into my project why can't it be found, yet there are no errors when importing?
The cholmod file is a pyx file which I've been told should not be a problem.
Please could anyone help, I am reasonably new to python and I am looking for a straight forward solution that won't be time consuming.
It was an issue with windows, I was able to fix this using the instructions on this link
https://github.com/EmJay276/scikit-sparse
We must follow these steps precisely:
(This was tested with a Anaconda 3 installation and Python 3.7)
Install these requirements in order:
'''
conda install -c conda-forge numpy - tested with v1.19.1
conda install -c anaconda scipy - tested with v1.5.0
conda install -c conda-forge cython - tested with v0.29.21
conda install -c conda-forge suitesparse - tested with v5.4.0
'''
Download Microsoft Build Tools for C++ from https://visualstudio.microsoft.com/de/visual-cpp-build-tools/ (tested with 2019, should work with 2015 or newer)
Install Visual Studio Build Tools
Choose Workloads
Check "C++ Buildtools"
Keep standard settings
Run ''' pip install git+https://github.com/EmJay276/scikit-sparse '''
Test ''' from sksparse.cholmod import cholesky '''
Use all the versions stated for numpy etc, however with scipy I installed the latest version and it worked fine.

Installation of dtaidistance in python provides error

I am trying to install the module dtaidistance in Python to calculate the DTW distance matrix for a set of time series. But whenever I try to install the package using "pip install dtaidistance" a large error pops up and I don't know how to interpret it and what to do in order to make it function.
See the final few lines and the corresponding error message after running the install in the anaconda prompt in the screenshot below:
Error code screenshot:
The error says the cl.exe binary is not found. This probably means that you have not installed the Microsoft C compiler and linker (MSVC or Microsoft Visual Studio for Windows).
By the way, the current version of DTAIDistance should continue installing the Python implementation but the fast C-based versions will not be available.

I cannot install dipy library for python, why ? In the description I explain what I did

I went to http://nipy.org/dipy/installation.html and install nibabel, then I when I wanted to install dipy, there where 2 problems:
Wheel was not built
and vcvarshall.bat not found.
What I did ?
Install Setuptools in site-pakcages
download Setuptools-34.3.1-py2.py3-none-any.whl (md5) and save in site-packages
I also try
python setup.py install --compiler=mingw32รง
and
If you get an error saying unable to find vcvarsall.bat then you need to create a file called pydistutils.cfg in notepad and give it the contents
[build]
compiler=mingw32
But setup.py de system it did not find, and I still have vcvarshall.bat not found.
what I need to do?
I am using, Windows 7, Python 3.5.1 and Anaconda 2.5.0 (64 bit)
You will almost certainly find it easier to install third-party packages if you adopt virtual environments. When done correctly you will then not need admin privileges to install packages into virtualenvs. The HitchHikers' Guide to Python contains more information about this.
The vcvarsall.bat is, I believe, a part of the Visual Studio (the Express version is available at no cost) environment. It's required when you are trying to build a compiled Python extension as described in this article. I'm not sure how that will play with mingw.
So, I installed via ANACONDA but , when I go to python, and I want to import dipy it says: No modle named dipy
Solved ! Well I had python 3.5 and dipy has some issues with that version, so I installed Anaconda with python 2.7 , installed visual c++9 and follow the steps on the web !

pystan: CompileError: command 'gcc' failed with exit status 1 (Windows)

Before I get to far into this, I should note that I have seen a very similar question, but the solution presented did not work for me. Perhaps one reason why is because that was Linux build and my current difficulty is on a Windows 7 machine. I use Cygwin to get access to the gcc (5.2.0) compiler suite.
In any event, I have been attempting to try out Stan via PyStan. I am working with an Anaconda (2.4.1 64-bit) distribution which I just updated today (Python 2.7.11). I initially tried to install PyStan via pip, but the install keeps failing due to what looks like the following error:
Cannot build msvcr library: "msvcr90d.dll" not found
Consequently, I used conda instead, which seemed to install just fine. (I should note that the conda install pushed my numpy back to an earlier version, which created conflicts with the pandas upon import. I just updated anaconda to deal with these broken dependencies.) I was also able to import PyStan without any problems. However, when I actually tried to fit a model (inside of a Jupyter Notebook), the process failed with the exception in the title.
The first thing I did was confirm that gcc was where in the referenced location (not shown in the title). Indeed it was, and it seemed to working just fine. I then tried to run the model as a script from the command line (still using Python), and it failed with the same error. When I recreated the model via the REPL, it pointed to a different location that had a .bat file referencing the (verified) compiler, and that failed as well.
I am pretty sure this is because I have Visual Studio 2012, instead of Visual Studio 2008. While it is possible for me to run parallel installations, if this code is going to be useful for others in the future, these are not reasonable hoops to jump through to make it happen. I was hoping that someone else might have a better explanation. Any info would be greatly appreciated.
Beneficial from the post at https://github.com/stan-dev/pystan/issues/306
I have met various error message, but finally, I install PyStan successfully.
My machine is also on Windows 7, x64 with Anaconda3 installed.Here are the procedures to install PyStan from the sourced codes.
Install Visual Studio 2017 & Visual Studio C++ Build Tool 2015 at http://landinghub.visualstudio.com/visual-cpp-build-tools
Update Conda
conda update conda
conda update --all
check the dependencies
pip install setuptool
conda install numpy cython matplotlib scipy pandas
Install gcc compiler components
conda install libpython
conda install -c msys2 m2w64-toolchain=5.3.0
created distutils.cfg file inside Anaconda3\Lib\distutils folder with the following:
[build]
compiler = mingw32
Download Git at https://git-scm.com/downloads
git clone --recursive https://github.com/stan-dev/pystan.git
Compile from the source code
python setup.py build --compiler=mingw32
python setup.py install
P.S. The solution for the issue: Cannot build msvcr library: "vcruntime140d.dll" not found.
Copy vcruntime140d.dll from C:\Windows\System32 to any folder, which is reachable in the path in the advanced system settings/environment variables/ system variables.

Using NumPy in Visual Studio

I downloaded http://pytools.codeplex.com/ (Python Tools for Visual Studio) so that I could write Python in Visual Studio.
The problem is when I try to use the most basic package "numpy" like so:
import numpy
It says "No module named 'numpy'."
How can I use NumPy and SciPy in Visual Studio?
Note: I am using Canopy Express on another machine which works perfectly; however, I don't want to install it on this machine since I already have Visual Studio installed.
I added the Python 3.3 environment to my Python "solution" by right-clicking Python environments and clicking add an environment. But, after right-clicking my environment and clicking install Python package, I typed in "numpy" and got this error when trying to install it:
...
creating build
creating build\src.win32-3.3
creating build\src.win32-3.3\numpy
creating build\src.win32-3.3\numpy\distutils
building library "npymath" sources
No module named 'numpy.distutils.msvccompiler' in numpy.distutils; trying from distutils
error: Unable to find vcvarsall.bat
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in c:\users\dom\appdata\local\temp\pip_build_Dom\numpy
Storing complete log in C:\Users\Dom\pip\pip.log
'numpy' failed to install. Exit code: 1
How can I install NumPy?
In Visual Studio 2013 Community Edition with a Python 2.7 environment, the following worked for me:
Open the Python Environments menu in Solution Explorer, and click on "Install Python Package..."
Then write "numpy":
Two solutions worked for me:
Going directly to my Python folder and installing the packages using pip.
Creating a virtual environment in my project and installing packages from within Visual Studio.
Consider using a more feature-rich Windows distribution of Python, like Anaconda. It comes with a boatload of packages included into the installer. This is quite handy for those who are new to Python, especially when they are using Windows.
Edit:
As of 2020, I would suggest using the python.org distribution of Python. Compiler issues on ms-windows have finally been fixed, so a lot of projects now provide binary packages (wheels) for ms-windows. Among others numpy, pandas, matplotlib, pillow, Cython and PyNaCl.
Note that wheel names ending in:
win_amd64.whl are for 64-bit versions of ms-windows, and
win32.whl are for 32-bit.
I actually ran into the same set of problems when trying to use Visual Studio for Python.
I managed to get things to work at the end - please see Using Visual Studio 2013 for Python (3.4) with NumPy and SciPy on Windows for details. Essentially you can either use the installer (if one is available) or use pip to do the installation.
Make sure C++ Common Tools are installed in Visual Studio:
See under Extra in the Visual Studio (Extra-Python-Interactive Window).
It has the ability to switch the interactive console through a different platform/Python version (32-bit, 64-bit, Debug, and Anaconda (which has the NumPy package)).
From PTVS Installation:
2. Installing packages individually
Here are some recommended packages. Generally you want to install packages using pip or through the interface in Visual Studio (which uses pip), as this will ensure that you get the latest version that will work with your version of Python, as well as any dependencies.
Some packages have complex dependencies and need to be downloaded manually, either from the project's website or from Christoph Gohlke's package collection.
I installed numpy and scipy from these links, and it works perfectly with Visual Studio.
numpy http://sourceforge.net/projects/numpy/files/NumPy/
scipy http://sourceforge.net/projects/scipy/files/scipy/
Matplotlib http://matplotlib.org/downloads.html
Pandas http://pandas.pydata.org/getpandas.html
Well, if anyone still has problem than what worked for me is:
C:/Users/DELL/AppData/Local/Programs/Python/Python39/python.exe -m pip install numpy
where the first part is simply the path of python.

Categories