Top2Vec import fails due to problems with numpy version conflicts - python

I'm facing an issue which seems to occur very often but the solutions I found so far did not helped me. When I try to do from top2vec import Top2Vec I get the following error:
ValueError Traceback (most recent call last)
<ipython-input-14-f6d7059c0d66> in <module>
----> 1 from top2vec import Top2Vec
2 model = Top2Vec(documents=data, speed="learn", workers=8)
~/env_env/lib/python3.7/site-packages/top2vec/__init__.py in <module>
----> 1 from top2vec.Top2Vec import Top2Vec
2
3 __version__ = '1.0.26'
~/env_env/lib/python3.7/site-packages/top2vec/Top2Vec.py in <module>
9 from gensim.parsing.preprocessing import strip_tags
10 import umap
---> 11 import hdbscan
12 from wordcloud import WordCloud
13 import matplotlib.pyplot as plt
~/env_env/lib/python3.7/site-packages/hdbscan/__init__.py in <module>
----> 1 from .hdbscan_ import HDBSCAN, hdbscan
2 from .robust_single_linkage_ import RobustSingleLinkage, robust_single_linkage
3 from .validity import validity_index
4 from .prediction import (approximate_predict,
5 membership_vector,
~/env_env/lib/python3.7/site-packages/hdbscan/hdbscan_.py in <module>
19 from scipy.sparse import csgraph
20
---> 21 from ._hdbscan_linkage import (single_linkage,
22 mst_linkage_core,
23 mst_linkage_core_vector,
hdbscan/_hdbscan_linkage.pyx in init hdbscan._hdbscan_linkage()
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
When I try to upgrade to numpy==1.20.0 like other solutions suggest than I get in trouble with other packages I need (as displayed in the ERROR warnings below)
ERROR: transformers 4.9.1 has requirement huggingface-hub==0.0.12, but you'll have huggingface-hub 0.0.15 which is incompatible.
ERROR: flair 0.8.0.post1 has requirement numpy<1.20.0, but you'll have numpy 1.20.0 which is incompatible.de here
Does anyone has an idea how to work around on this or was facing the similar issue? I would appreciate every kind of hint!!! Thanks in advance!

I have faced the same issue. I Just installed top2vec==1.0.20 this version of Top2Vec using pip, without upgrading Numpy, and also it required joblib library too.
So install both.

Related

issue importing module in python jupyter

hi so I'm trying to import geopandas into my script
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
#handling txt
#remove 'lat=' and 'long=' then type change from object to float to make point.
df = pd.read_csv('latlong.txt', header=None, names = ['lat','long', 'name','description'])
df['lat'] = df['lat'].str.replace('lat=', '')
df['long'] = df['long'].str.replace('long=', '')
df['lat'] = df['lat'].astype(float)
df['long'] = df['long'].astype(float)
#make point geometry
df['geometry'] = df.apply(lambda row: Point(low['long'], low['lat']), axis=1) #long is X, lat is Y
#change df to gdf
gdf = gpd.GeoDataFrame(df, geometry = 'geometry', crs='EPSG:4326') #epsg4326 is WGS84
But when I try to run this in the jupyter notebook, using a conda environment from these steps: https://medium.com/#nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084
I get the following error :
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_2312/3230284861.py in <module>
----> 1 import pandas as pd
2 import geopandas as gpd
3 from shapely.geometry import Point
4
5 #handling txt
~\.conda\envs\geojsongen\lib\site-packages\pandas\__init__.py in <module>
14
15 if missing_dependencies:
---> 16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "C:\Users\User\.conda\envs\geojsongen\python.exe"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I installed the geopandas in this environment using the following command:
conda install -c conda-forge geopandas
Could someone advise me on how I can fix these errors? Any help is appreciated, thank you!!
edit:
I tried this pip install --upgrade --force-reinstall numpy, thanks #krmogi for this, but now I get this error, it looks like an issue with my geopandas installation? :
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13932/3230284861.py in <module>
1 import pandas as pd
----> 2 import geopandas as gpd
3 from shapely.geometry import Point
4
5 #handling txt
~\.conda\envs\geojsongen\lib\site-packages\geopandas\__init__.py in <module>
----> 1 from geopandas._config import options # noqa
2
3 from geopandas.geoseries import GeoSeries # noqa
4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in <module>
107 use_pygeos = Option(
108 key="use_pygeos",
--> 109 default_value=_default_use_pygeos(),
110 doc=(
111 "Whether to use PyGEOS to speed up spatial operations. The default is True "
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in _default_use_pygeos()
93
94 def _default_use_pygeos():
---> 95 import geopandas._compat as compat
96
97 return compat.USE_PYGEOS
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_compat.py in <module>
7 import numpy as np
8 import pandas as pd
----> 9 import pyproj
10 import shapely
11 import shapely.geos
~\.conda\envs\geojsongen\lib\site-packages\pyproj\__init__.py in <module>
47 import warnings
48
---> 49 import pyproj.network
50 from pyproj._datadir import ( # noqa: F401 pylint: disable=unused-import
51 _pyproj_global_context_initialize,
~\.conda\envs\geojsongen\lib\site-packages\pyproj\network.py in <module>
8 import certifi
9
---> 10 from pyproj._network import ( # noqa: F401 pylint: disable=unused-import
11 _set_ca_bundle_path,
12 is_network_enabled,
ImportError: DLL load failed while importing _network: The specified module could not be found.
Your issue is happening here as shown in your traceback
----> 1 import pandas as pd
Make sure you have pandas installed.
pip install pandas
It also says that numpy C-extentions failed. Install numpy as well:
pip install numpy
While you're at it, make sure you have the other modules installed as well.
If you're still getting the same error, it's possible that setuptools is not properly installed. Do this:
pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
If you still don't have any luck, try this:
pip install --upgrade --force-reinstall numpy

Issue with hdbscan (ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject)

I know a number of people have posted about this before but I still can't resolve my error. I'm trying to import hdbscan but it keeps returning the following error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-bf3184c2d1a0> in <module>
2 import numpy as np
3 from pyproj import Transformer
----> 4 import hdbscan
5 from scipy.spatial.qhull import ConvexHull
6 from shapely.geometry import Point
~/Library/Python/3.7/lib/python/site-packages/hdbscan/__init__.py in <module>
----> 1 from .hdbscan_ import HDBSCAN, hdbscan
2 from .robust_single_linkage_ import RobustSingleLinkage, robust_single_linkage
3 from .validity import validity_index
4 from .prediction import (approximate_predict,
5 membership_vector,
~/Library/Python/3.7/lib/python/site-packages/hdbscan/hdbscan_.py in <module>
19 from scipy.sparse import csgraph
20
---> 21 from ._hdbscan_linkage import (single_linkage,
22 mst_linkage_core,
23 mst_linkage_core_vector,
hdbscan/_hdbscan_linkage.pyx in init hdbscan._hdbscan_linkage()
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
I have tried uninstalling numpy 1.19.5 and installing numpy 1.20 but it hasn't worked for me. I have installed the package hdbscan 0.8.27, I'm using Python 3.7.2 and I do not have admin rights to my MacBook. Appreciate any help!!
I had the same issue.
I installed the hdbscan using the below method:
!pip install hdbscan --no-build-isolation --no-binary :all:
also installed the numpy 1.9.2
It works for me.

I am facing this issue in seaborn import:

When I try running following line in Jupiter notebook
> import seaborn as sns
I get this error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-ed9806ce3570> in <module>()
----> 1 import seaborn as sns
~/anaconda3/lib/python3.6/site-packages/seaborn/__init__.py in <module>()
8 from .palettes import *
9 from .regression import *
---> 10 from .categorical import *
11 from .distributions import *
12 from .timeseries import *
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in <module>()
5 from scipy import stats
6 import pandas as pd
----> 7 from pandas.core.series import remove_na
8 import matplotlib as mpl
9 from matplotlib.collections import PatchCollection
ImportError: cannot import name 'remove_na'
dependency versions are listed below:
Python 3.6.3
conda 4.8.2
numpy 1.18.0
pandas 1.0.1
scipy 1.1.0
matplotlib 3.1.3
What is the issue here?
Okay,
so I still dont know, what was wrong in this, but I did solve the problem.
I simply uninstalled seaborn
pip3 uninstall seaborn
and installed it again
pip3 install seaborn
it worked, no error this time.
But I still dont know, what went wrong first time.
If someone can help please share.
The problem is that seaborn seems to be using a private method from pandas. The issue has been reported to both pandas and seaborn developers (see https://github.com/pandas-dev/pandas/issues/16971 and https://github.com/mwaskom/seaborn/pull/1241) which both published a fix in later versions.
The fixed version is available on pip but not on Ubuntu's packages yet (as of August 2020).
However, for those who don't want pip install, the fix is straightforward and can be manually applied (see the pull request above).

No module named 'sklearn.neighbors._base'

I have recently installed imblearn package in jupyter using
!pip show imbalanced-learn
But I am not able to import this package.
from tensorflow.keras import backend
from imblearn.over_sampling import SMOTE
I get the following error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-20-f19c5a0e54af> in <module>
1 # from sklearn.utils import resample
2 from tensorflow.keras import backend
----> 3 from imblearn.over_sampling import SMOTE
4
5
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/__init__.py in <module>
32 Module which allowing to create pipeline with scikit-learn estimators.
33 """
---> 34 from . import combine
35 from . import ensemble
36 from . import exceptions
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/__init__.py in <module>
3 """
4
----> 5 from ._smote_enn import SMOTEENN
6 from ._smote_tomek import SMOTETomek
7
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/_smote_enn.py in <module>
8 from sklearn.utils import check_X_y
9
---> 10 from ..base import BaseSampler
11 from ..over_sampling import SMOTE
12 from ..over_sampling.base import BaseOverSampler
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/base.py in <module>
14 from sklearn.utils.multiclass import check_classification_targets
15
---> 16 from .utils import check_sampling_strategy, check_target_type
17
18
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/__init__.py in <module>
5 from ._docstring import Substitution
6
----> 7 from ._validation import check_neighbors_object
8 from ._validation import check_target_type
9 from ._validation import check_sampling_strategy
~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/_validation.py in <module>
11
12 from sklearn.base import clone
---> 13 from sklearn.neighbors._base import KNeighborsMixin
14 from sklearn.neighbors import NearestNeighbors
15 from sklearn.utils.multiclass import type_of_target
ModuleNotFoundError: No module named 'sklearn.neighbors._base'
Other packages in the environment
numpy==1.16.2
pandas==0.24.2
paramiko==2.1.1
matplotlib==2.2.4
scikit-learn==0.22.1
Keras==2.2.4
tensorflow==1.12.0
tensorboard==1.12.0
tensorflow-hub==0.4.0
xlrd==1.2.0
flask==1.0.2
wtforms==2.2.1
bs4==0.0.1
gensim==3.8.1
spacy==2.2.3
nltk==3.4.5
wordcloud==1.6.0
pymongo==3.10.1
imbalanced-learn==0.6.1
I checked the sklearn package, it contains base module, not _base. But modifying it may not be the right solution. Any other solution to fix this issue.
If in case you want to persist with the latest version of scikit-learn, add the following code to your script or execute the following code in your environment before installing imblearn
import sklearn.neighbors._base
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
This has to be after
pip install sklearn
or in a notebook environment:
!pip install sklearn
This problem stems from the fact that certain modules are named with an underscore in the newer scikit-learn releases
Previous sklearn.neighbors.base has been renamed to sklearn.neighbors._base in version 0.22.1.
You have probably a version of scikit-learn older than that.
Installing the latest release solves the problem:
pip install -U scikit-learn
or
pip install scikit-learn==0.22.1
I had a similar problem trying to import SMOTE from imblearn.over_sampling and my version of scikit-learn was up to date (0.24.1). What worked for me was:
First I downgraded my scikit learn version to 0.22.1 using
pip install scikit-learn==0.22.1
Next, I updated the imbalanced-learn package using:
pip install -U imbalanced-learn
That uninstalled scikit-learn-0.22.1, installed the updated version (scikit-learn-0.24.1), and updated the imbalanced-learn package. Everything worked fine thereafter.
If it is in a particular env, you must copy the _base file or base file to the env from package file.
I had the same problem in my tensorflow env. I just copied _base and base file to my tensorflow env and worked.

ImportError: cannot import name murmurhash3_32

I am trying to use the sklearn.qda package in python. I have installed it successfully but when Itry to import it I get the error message below. Can anybody tell me what should I do to fix this?
In [3]: from sklearn.qda import QDA
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-7d7abf937d66> in <module>()
----> 1 from sklearn.qda import QDA
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/qda.py in <module>()
12
13 from .base import BaseEstimator, ClassifierMixin
---> 14 from .utils.fixes import unique
15 from .utils import check_arrays, array2d
16
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/utils/__init__.py in <module>()
7 import warnings
8
----> 9 from .murmurhash import murmurhash3_32
10 from .validation import (as_float_array, check_arrays, safe_asarray,
11 assert_all_finite, array2d, atleast2d_or_csc,
ImportError: cannot import name murmurhash3_32
I had the same problem, I run:
sudo pip install -U scikit-learn
and now everything is working fine
I started a new shell and this problem went away
I faced the similar situation of getting mumurhash error while installing sklearn.preprocessing library.
I upgraded numpy version from 1.13 to 1.15
using
pip install --upgrade numpy
After this, I was able to import the sklearn library.
I fixed this by upgrading murmurhash to 1.0.5.
I faced a similar problem, so there are mainly two solutions
Either run it in administrator mode and install all the libraries and run in admin mode. Something that I would not recommend
Use virtualenv to install the libraries again and run your command in the virtualenv. This worked for me.
Hope this helps

Categories

Resources