Cannot import category_encoders module - python

I am not able to import category_encoders module in jupyter notebook in python 3 virtual environment.
Error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-86725efc8d1e> in <module>()
9 from plotly import graph_objs
10 from datetime import datetime
---> 11 import category_encoders as ce
12
13 import sklearn
ModuleNotFoundError: No module named 'category_encoders'
Output of "which pip"
/opt/virtual_env/py3/bin/pip
Output of "pip show category_encoders" is
Name: category-encoders
Version: 1.3.0
Summary: A collection sklearn transformers to encode categorical variables as numeric
Home-page: https://github.com/wdm0006/categorical_encoding
Author: Will McGinnis
Author-email: will#pedalwrencher.com
License: BSD
Location: /opt/virtual_env/py3/lib/python3.6/site-packages
Requires: numpy, pandas, statsmodels, scikit-learn, patsy, scipy
Required-by:
Output of "pip list"
Package Version
------------------- -------
absl-py 0.7.0
astor 0.7.1
backcall 0.1.0
category-encoders 1.3.0
cycler 0.10.0

pip install --upgrade category_encoders
Now,
Restart your kernel
import category_encoders as... so on and so forth
Also,
you can checkout the sk-learn's preprocessing class CategoricalEncoder...
from sklearn.preprocessing import CategoricalEncoder
get sk-learn from here,
pip install git+git://github.com/scikit-learn/scikit-learn.git
or Simply
pip install sklearn

I was using anaconda environment.
Initially, I installed category_encoders using pip (within the conda enviornment) and it failed to resolve. Then I uninstalled ``category_encoders` from pip
pip uninstall category-encoders
and installed it using conda:
conda install -c conda-forge category_encoders
That solved the issue.

If you have given your virtual environment ('py3' for your case) the permission for accessing the system site-packages directory you can try installing the package to your base (root) environment.
Search 'pyvenv.cfg' file in your system and check if it includes:
include-system-site-packages = true
If yes, install the package to your root environment as stated here and try importing it again in your Jupyter Notebook.

You can add a cell above and type ! pip install --upgrade category_encoders
It will install the package without opening a terminal window.

Related

module 'scipy.stats._continuous_distns' has no attribute 'frechet_r_gen'

When
import lmoments3 as lm
from lmoments3 import distr
I get module 'scipy.stats._continuous_distns' has no attribute 'frechet_r_gen'
I cded into scipy/stats folder, and there is no presence of 'frechet_r_gen'
I have tried pip install update scipy lmoments3 and pip install --user scipy
I am using conda environments.
https://docs.scipy.org/doc/scipy/release.1.6.0.html
This distribution was removed in scipy 1.6.0. So either install scipy 1.5.4 or make this lmoments3 module update to a more recent scipy version.

Anaconda-Error: cannot import name Transformer from pyproj

I try to install Transformer from pyproj and get the message "cannot import name".
I installed pyproy using Anaconda Navigator. There it tells me I have version 1.9.6. (newest update). I found a thread about same issue but it didn't help me (cannot import name Transformer from pyproj).
I checked pyproj-Documentation and installed via terminal conda install -c conda-forge proj-datumgrid-europe proj-datumgrid-north-america proj-datumgrid-oceania proj-datumgrid-world.
Not sure if that's the right thing to do. I'm a noob .-. help is appreciated.
ImportError Traceback (most recent call last)
/var/folders/jy/1f2tlvb965g30zhw9q3cvdw07r5rb_/T/ipykernel_49825/1776791710.py in <module>
4 from shapely.geometry import Point, LineString
5 import pyproj as pi
----> 6 from pyproj import Transformer
ImportError: cannot import name 'Transformer' from 'pyproj' (/Users/vob/opt/anaconda3/envs/geopandas/lib/python3.8/site-packages/pyproj/__init__.py)
The latest version of pyproj is 3.3 at the moment. To update, recommend looking at pyproj installation instructions: https://pyproj4.github.io/pyproj/stable/installation.html
Here is a snippet:
conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda create -n pyproj_env pyproj
conda activate pyproj_env

How to know torch version that installed locally in your device

I want to check torch version in my device using Jupyter Notebook.
I'm used this
import torch
print(torch.__version__)
but it didn't work and Jupyter notebook raised an error as below
AttributeError Traceback (most recent call last)
<ipython-input-8-beb55f24d5ec> in <module>
1 import torch
----> 2 print(torch.__version__)
AttributeError: module 'torch' has no attribute '__version__'
Is there any command to check torch version using Jupyter notebook?
Try this. Open your terminal
python3 -c "import torch; print(torch.__version__)"
I have tried to install new Pytorch version. But, it didn't work and then I deleted the Pytorch files manually suggested on my command line. Finally, I installed new Pytorch version using conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch and everything works fine.
This code works well after that.
import torch
print(torch.__version__)
You can check list all installed python modules with version tag via pip.
To ensure running the proper pip version, just execute it via the python interpreter:
# python symlink
python -m pip freeze
# python3
python3 -m pip freeze
You can grep for the module of question (used numpy as an example)
python -m pip freeze | grep numpy
numpy==1.19.4
If in the terminal, use pip.
user#debian:~/..$ pip3 show torch
Name: torch
Version: 1.11.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages#pytorch.org
License: BSD-3
Location: /home/user/.local/lib/python3.7/site-packages
Requires: typing-extensions
Required-by: torchaudio, torchvision

pip install geopandas on windows

I am relatively new to python and trying to install geopandas on python 3.7 using pip. For separate reasons, I would like to avoid using the anaconda distribution. Following this post, I was able to successfully install geopandas by first installing the dependencies manually. The problem is that now I run into a problem when I try to import geopandas:
import geopandas
The subsequent error message is:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\geopandas\__init__.py", line 5, in <module>
from geopandas.io.file import read_file
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\geopandas\io\file.py", line 4, in <module>
import fiona
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fiona\__init__.py", line 87, in <module>
from fiona.collection import BytesCollection, Collection
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fiona\collection.py", line 9, in <module>
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: DLL load failed: The specified module could not be found.
Any advice would be greatly appreciated
My case is similar to yours. And here is how I got mine setup:
Platform: Windows 10, 64-bit Python Version: Python 3.7
Dependencies (whl files needed):
GDAL‑3.0.4‑cp37‑cp37m‑win_amd64.whl
Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl
pyproj‑2.6.0‑cp37‑cp37m‑win_amd64.whl
Rtree‑0.9.4‑cp37‑cp37m‑win_amd64.whl
Steps:
Download the files that match the platform and Python version from
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Install packages (stick with the order)
a) C:\Users...\Python37\Scripts>pip3.7 install C:...\GDAL‑3.0.4‑cp37‑cp37m‑win_amd64.whl
b) C:\Users...\Python37\Scripts>pip3.7 install C:...\Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl
c) C:\Users...\Python37\Scripts>pip3.7 install C:...\pyproj‑2.6.0‑cp37‑cp37m‑win_amd64.whl
d) C:\Users...\Python37\Scripts>pip3.7 install C:...\Rtree‑0.9.4‑cp37‑cp37m‑win_amd64.whl
Given no errros, now it's good to go:
C:\Users...\Python37\Scripts>pip3.7.exe install geopandas
Test it using IDEL 3.7.4
import geopandas as pdg
(It works!)
This works for me and I hope this is also helpful for you.
I had trouble installing geopandas on (win-64, Spyder3.8, Python3.8.3)
Use this expression to install geopandas in anaconda prompt:
conda install -c conda-forge/label/cf202003 geos
(do not use this website: https://geopandas.org/install.html)
(do not use this expression: conda install --channel conda-forge geopandas)
The simplest method to install geopandas is:
conda install geopandas
In order to update geopandas to latest version use the following command after installation by conda:
pip install geopandas --upgrade
There are other installation methods also explained in Geopandas official website.
Conda is really powerful when it comes to installation as it will install the dependencies needed by the package. However, if you would like to install dependencies earlier than use the following command:
conda install pandas fiona shapely pyproj rtree descartes
Note that if you have installed the dependencies using above command then you can also use pip to install geopandas but before installing via pip dependencies are required to be installed. In order to read more about dependencies, please follow the official guide. To install using pip use the following command:
pip install geopandas

Python 3 ImportError: cannot import name 'model selection' OS X 10.11.3, Anaconda

Python 3.5.1 |Anaconda 4.0.0 (x86_64)on OS X 10.11.3
>>> from sklearn import pipeline, model_selection
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'model_selection'
tried to:
upgrade six, sk-learn,
sudo pip uninstall python-dateutil
sudo pip install python-dateutil==2.2
pip2 install six -U
pip install --ignore-installed six
pip install --ignore-installed ipython
even reinstall the anaconda...
Did NOT fixed.
Thanks for help
_________Updata________
I have checked that my six version is the newest one (version = "1.10.0")
import sklearn
sklearn.version
'0.17.1'
I found that there is no folder name "model_selection" in sklearn folder. But there is this folder in https://github.com/scikit-learn/scikit-learn/tree/3078d7d611329c46777d4004a1185a3626558efe/sklearn.
After install the dev version by
$ pip install git+git://github.com/scikit-learn/scikit-learn.git
Successfully installed scikit-learn-0.18.dev0
And then run a script which runs successfully in 0.17.1, it shows error:
from .pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
ImportError: dlopen(/Users/Username/anaconda3/lib/python3.5/site-packages/sklearn/metrics/pairwise_fast.cpython-35m-darwin.so, 2): Library not loaded: libmkl_intel_lp64.dylib
Referenced from: /Users/Username/anaconda3/lib/python3.5/site-packages/sklearn/metrics/pairwise_fast.cpython-35m-darwin.so
Reason: image not found
What version of scikit-learn are you using? It looks like the latest, when I install for Python 3.5, is 0.17.1. Checking in the console:
import sklearn
sklearn.__version__
'0.17.1'
According to the documentation for this version that "model_selection" package doesn't exist. It does exist in the dev version. This should be why it is complaining.

Categories