How do I install the shap module on Mac? - python

I am trying to install the shap package and keep getting the following error
ModuleNotFoundError: No module named 'shap'
I have typed the following into my notebook as well as terminal
!conda install -c conda-forge shap
!conda install shap --yes
Here are the lines of the that are erroring out
!pip install shap
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
I am currently on a Mac

I got same issue using pip install shap command. However, conda install worked. I use Mac.
conda install -c conda-forge shap

I am on Mac OS Big Sur with pip 21.2.4 and Python 3.8.9. I am able to install shap with the following command.
ARCHFLAGS="-arch x86_64" pip3 install shap

This about a similar issue.It may help you.
Modules are installed using pip on OSX but not found when importing
If the above doesn't work, Try this:
uninstall and reinstall SHAP
Update Numpy to the latest version, then:
pip install git+https://github.com/slundberg/shap.git
if the above doesn't work, then maybe this:
To install shapely (https://pypi.org/project/Shapely/)? In python, you can install shapely by doing
pip install shapely
For windows shapley can be installed by downloading .whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and do
pip install <name of whl file>
or if you are using anaconda you can use conda-forge to get shapely
conda config --add channels conda-forge
conda install shapely

Related

Running setup.py install for fbprophet ... error

I cannot install fbprophet or gcc7.
I have manually installed a precompiled ephem.
Running setup.py install for fbprophet ... error
I have tried with python 3.6 and 3.7. I have tried running as administrator and without.
My anaconda prompt cannot install anything without throwing errors. I would rather use pip.
The problem may be related to pystan.
File "d:\python37\lib\site-packages\pystan\api.py", line 13, in <module> import pystan._api # stanc wrapper
ImportError: DLL load failed: The specified module could not be found.
I am using windows 10.
Use:
The first step is to remove pystan and cache:
pip uninstall fbprophet pystan
pip --no-cache-dir install pystan==2.17 #any version
pip --no-cache-dir install fbprophet==0.2 #any version
conda install Cython --force
pip install pystan
conda install pystan -c conda-forge
conda install -c conda-forge fbprophet
It creates a wheel and update the environment necessary for the package. pip install fbprophet creates the similar issue.
Be sure that pystan is working.
import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling().extract()['y']
y.mean() # with luck the result will be near 0
Use this link: Installing PyStan on windows
Reason: The python distribution on Anaconda3 uses an old version of gcc (4.2.x)
Please use anaconda prompt as administrator
set a new environment for a stan
conda create -n stan python=<your_version> numpy cython
install pystan and gcc inside the virtual environment.
conda activate stan
or
source activate stan
(stan) pip install pystan
(stan) pip install gcc
verify your gcc version:
gcc --version
gcc (GCC) 4.8.5
To solve this problem, I uninstalled my existing python 3.7 and anaconda. I re-installed anaconda with one key difference.
I registered Anaconda as my default Python 3.7 during the Anaconda installation. This lets visual studio, PyDev and other programs automatically detect Anaconda as the primary version to use.
I tried to import fbprophet on Python Anaconda, however, I got some errors.
This code works for me..
conda install -c conda-forge/label/cf201901 fbprophet
(Short n Sweet) For Mac users :
pip3 uninstall pystan
pip3 install pystan==2.17.1.0
pip3 install fbprophet
I used the following steps to install fbprophet 0.7.1 on windows 10 (2022-03-10):
Install anaconda here.
Install pystan by following this guide. The main line I used was conda install libpython m2w64-toolchain -c msys2. Then, install pystan using pip install pystan
Check your installation by running the following in a python terminal:
>>> import pystan
>>> model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
>>> model = pystan.StanModel(model_code=model_code)
>>> y = model.sampling().extract()['y']
>>> y.mean() # with luck the result will be near 0
If the above works, proceed to install fbprophet with pip install fbprophet
Hope this works for you!
If all of the answers did not work lets clone pystan and do not use the above solutions:
git clone --recursive https://github.com/stan-dev/pystan.git
cd pystan
python setup.py install
It looks like fbprophet renamed to prophet on the FB side, so this command worked for me (Windows 10 + VSCode + Python 3.10.2)
pip install prophet --no-cache-dir

How to install fbprophet for Python 3.7 (anaconda distribution)

I attempted to use fbprophet for time series analysis using Python.
I ran from fbprophet import Prophet but got No module named 'fbprophet'
I think fbprophet is not part of packages that comes with anaconda distribution
I went ahead to install fbprophet but got this error message No module named 'fbprophet'
I am on Windows 10, 64 bits
I install anaconda distribution of anaconda 3.7
I have ran conda install -c conda-forge fbprophet and conda install -c conda-forge/label/cf201901 fbprophet on my anaconda prompt which it rolled endlessly
I have also ran pip install fbprohet which did not work as well
I ran pip list which worked but prophet or fbprophet not among the list
I have searched this site for relevant questions and tried all what I clues I got in it but did not work for me.
Option 1
conda install -n [NameOfVEnv] -c conda-forge fbprophet
Where -c stands for "channel" which is
the locations where Navigator and conda look for packages. (Source)
and -n for "Name of environment".
I just tried here (on CentOS 7) and it worked fine.
Option 2
An alternative, if one is using Windows 10, is to access Anaconda Prompt for the environment that you are working with as admin:
And run
conda install -c conda-forge fbprophet
I just tried here (on Windows 10 64-bit) and it worked fine.
Option 3
Prophet is on PyPI, so you can use pip to install it (Source)
# bash
# Install pystan with pip before using pip to install fbprophet
$ pip install pystan
$
$ pip install fbprophet
You may need to install dependencies (in both options), but it asks you in the prompt window. If it appears, you will need to enter Y.
I installed this way:
pip install pystan==2.19.1.1
then:
pip install prophet
It seems that currently pystan version 3 is not working properly.
(Tested on MacOS)
You can check this official github link where the detailed steps for installation is given. This library is supported only in Python 3.
Open cmd, run this command -
pip install pystan==2.19.1.1
Then run this-
pip install prophet
First install
pip install httpstan
Then Install
pip install pystan
Then Install
pip install fbprophet
I had the same issue, but none of the answers mentioned here worked (Windows 10 machine). What worked was the following:
conda config --add channels conda-forge
conda install anaconda
Above step took almost 25 hours for me. Do above only if you get this error "The environment is inconsistent, please check the package plan carefully"
pip install pystan==2.19.1.1
conda install python=3.8 (fbprophet did not work on Python 3.9)
conda install numpy=1.19.0
conda install fbprophet=0.7.1
you just search the wrong letter, please enter pip search fbprophet,in the way, i can get two
fbprophet did not work on Python 3.9
It is a very important information, after downgrading Python from 3.9 to 3.8, I use 'conda install fbprophet' install fbprophet successfully
Use conda install gcc to set up gcc. The easiest way to install Prophet is through conda-forge: conda install -c conda-forge prophet.

ModuleNotFoundError: No module named 'imblearn'

I tried running the following code:
from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE
sm = SMOTE(random_state=12, ratio = 1.0)
x_SMOTE, y_SMOTE = sm.fit_sample(X, y)
which gives me the error message:
ModuleNotFoundError: No module named 'imblearn'
I have tried installing the imblearn module in multiple ways, they all seem to work (there are no errors given during the installation but when I run the above code, I get an error message).
I tried istalling imblearn using the following suggested in other stackoverflow questions:
pip install -U imbalanced-learn
pip install imblearn
!pip install imblearn
pip install -c glemaitre imbalanced-learn
pip install imblearn==0.0
None of these seem to help... Any ideas? Thank you!
I installed the module named imblearn using anaconda command prompt.
conda install -c conda-forge imbalanced-learn
Then imported the packages
from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE
Again, I tried to install imblearn through pip, it works for me.
(base) C:\WINDOWS\system32>pip install -U imbalanced-learn
Requirement already up-to-date: imbalanced-learn in c:\users\ashok\anaconda3\lib\site-packages (0.4.3)
Requirement already satisfied, skipping upgrade: numpy>=1.8.2 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (1.15.3)
Requirement already satisfied, skipping upgrade: scipy>=0.13.3 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.19.1)
Requirement already satisfied, skipping upgrade: scikit-learn>=0.20 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.20.0)
On AWS SageMaker, follow the documentation:
!pip install imbalanced-learn
in a notebook cell.
This worked for me
First install the package in your environment:
pip install -U imbalanced-learn
Next:
conda install -c conda-forge imbalanced-learn
Open anaconda prompt and install below module:
conda install -c conda-forge imbalanced-learn
conda install -c conda-forge/label/gcc7 imbalanced-learn
conda install -c conda-forge/label/cf201901 imbalanced-learn
Those who have permission issue or failed to install it can follow this.
conda create --name dsc_new
conda activate dsc_new
conda install -c conda-forge imbalanced-learn
try on your notebook pip install imbalanced-learn --user
I have been fixed it by applying the following inside a Jupyter Notebook.
!pip install imbalanced-learn==0.6.0
!pip install scikit-learn==0.22.1
I had the same issue which was rectified by using:
!pip install -U imbalanced-learn
Then this:
conda install -c conda-forge imbalanced-learn
Updated my conda:
conda update -n base -c conda-forge conda
Restarted the kernel.
try this way:
from imblearn import under_sampling
from imblearn import over_sampling
from imblearn.over_sampling import SMOTE
OR
import imblearn *
I've come across the same problem a few days ago - trying to use imblearn inside a Jupyter Notebook. This question led me to the solution:
conda install -c glemaitre imbalanced-learn
Notice, one of the commands you tried (pip install -c glemaitre imbalanced-learn) doesn't make sense: -c glemaitre is an argument for Anaconda python distributions, which tells conda (Anaconda's CLI) to download the module from a source different than the defaults (glemaitre's channel). Since that argument is conda-specific, it doen't apply to pip commands.
Using python=3.6.10 and below worked for me.
I was dealing with the same problem. Updating packages, upgrading pip or python version did not resolve the problem for me.
The issue was that pip installed package to one folder, but my jupyter notebook imported packages from another folder. To get the path from where your packages are imported, you may use:
import site
site.getsitepackages()
# /your/path/from/python
Then you may check in terminal where pip installs your packages :
pip show imblearn
If the paths do not coincide, you may manually set the path for pip in terminal:
pip config set global.target /your/path/from/python
And install your package again by
pip install imblearn
If you are still experiencing error after installing imblearn either on Anaconda terminal while using Vscode. Try to restart Vscode for it to reflect.

python: install dash with conda

How can I install dash step-by-step?
I'm really new at importing packages in python. I have python 3.6.4 on my computer and I'm trying to install the dash package, dash_core_components.
I tried to type in the anaconda prompt: conda install dash (not available for current channels)
I also tried to install pip through conda: conda install pip then pip install dash ... but got an error also.
I'm really new and honestly don't really know what I'm doing. I got a pop-up from spyder when I open it saying to never use pip, it can break stuff. I don't understand why.
Here are the commands to get conda to install dash:
conda install -c conda-forge dash-renderer
conda install -c conda-forge dash
conda install -c conda-forge dash-html-components
conda install -c conda-forge dash-core-components
conda install -c conda-forge plotly
If you go to the Anaconda site and search for the package they will give you the conda command to install the package.
Along with the others. You can also try the following:
import pip
pip.main(['install', 'dash-renderer', '--user'])
pip.main(['install', 'dash', '--user'])
pip.main(['install', 'dash-html-components', '--user'])
pip.main(['install', 'dash-core-components', '--user'])
pip.main(['install', 'plotly', '--user'])
Note: This will install the packages only for the current session.
or
Try the following too:
!pip install dash-renderer
!pip install dash
!pip install dash-html-components
!pip install dash-core-components
!pip install plotly
Per most recent update from Dash website, the below should now be sufficient:
pip install dash==1.8.0
Note: starting with dash 0.37.0, dash automatically installs
dash-renderer, dash-core-components, dash-html-components, and
dash-table, using known-compatible versions of each. You need not and
should not install these separately any longer, only dash itself.
Per Lucas's comment above, with Anaconda distribution use :
conda install -c conda-forge dash
Try one of the following:
conda install -c conda-forge dash
conda install -c conda-forge/label/broken dash
It worked for me for a different package (opencv). Source at this link from anaconda.org

Install utils package in python facing with error Package not found

I tried to install utils Python package using Anaconda but I ended up with this error:
Package missing in current win-64 channels
I tried:
conda install -c bioconda utils, but still the same. Can anyone help me fix it?
to install run:
pip install python-utils
to import:
import python_utils
worked fine on jupyter notebook ubuntu 16.04
Install:
pip install utils
Import:
import utils
Try run:
conda install --channel bioconda/label/bioconda-utils-test package
or
conda install -c conda-forge python-utils
I succeed using following instructions:
The package can be installed through pip (this is the recommended method):
pip install python-utils
Or if pip is not available, easy_install should work as well:
easy_install python-utils
for more details please refer to https://pypi.org/project/python-utils/
however, I failed using Влад Давидченко's answers.
Once you have installed python-utils with:
conda install --name myenv python-utils
You can then reference the package by using:
from python_utils import *

Categories