Gensim package installation/word2vec not recognised - python

from gensim.models import Word2Vec
results in the following error
ImportError: cannot import name 'Word2Vec' from 'gensim.models' (unknown location)
from gensim.models.word2vec import Word2Vec
results in the same error
After deleting all conda installations of this package, pip uninstalling gensim, pip installing gensim and pip install --upgrade gensim, I can finally do
import gensim
but when I try to use gensim.models.Word2Vec it results in the error:
AttributeError: module 'gensim.models' has no attribute 'Word2Vec'
Edit: updated Numpy and Scipy as well
Note: I am using a jupyter notebook that I run from my local machine. I have not had this problem using Pycharm where I was running gensim from a conda env (but I'm working on a group project in notebook so it would be nice if I didn't constantly have to copy paste between these 2 workspaces...)
Any help would be appreciated

First, try to restart your kernel after the installation and see if it works. Then, check that your are in the right virtual environment. Then, please check you gensim version. In a notebook cell run
import gensim
gensim.__version__ # should be 4.1.2. If it's not update via pip.
You can also manually inspect if gensim.models.word2vec is actually there. In a notebook cell run
gensim.__path__
and go to the folder. Here you can see if there's indeed a folder named models and a script named word2vec. If not, there's something wrong with your installation. Hope this helps a bit.

Related

ModuleNotFoundError: No module named 'tensorflow.python.trackable'

The statement is:
from tensorflow.python.trackable import base as trackable
But the module not found error is coming up.
##### File "C:\Users\mahit\anaconda3\lib\site-packages\keras\dtensor\lazy_variable.py", line 26, in <module>
from tensorflow.python.trackable import base as trackable
ModuleNotFoundError: No module named 'tensorflow.python.trackable'
The piece of code is inside keras library. I dont understand why this module not found error is coming up. Becase this is a code that came with the package. Also not sure what trackable does. Please help me resolve this.
The solution for me was to install keras in version 2.9.0
pip install keras==2.9.0
I got rid of this error: uninstall tensorflow and install tf-nightly. Nevertheless, I got another error: Can't find libdevice directory ${CUDA_DIR}/nvvm/libdevice
In python code, with Linux OS, that error could be solved by using command: os.environ['XLA_FLAGS'] = '--xla_gpu_cuda_data_dir=/usr/lib/cuda/'
I had the same problem for the past one month and I was not able to resolve it. Then finally I just uninstalled tensorflow and installed tf-nightly with immediately resolved the issue.
The issue occurs as tensorflow recently moved the keras out of the default package and now is only available through the tf-nightly install.
Hope this resolves the issue
I have the same issue and have been check the current dir of tensorflow, the trackable folder does not exist.
So here is an easy way.
Git clone from the url: https://github.com/tensorflow/tensorflow
Find the tensorflow -> python -> trackable
Copy the trackable folder to your tensorflow install dir (For example: C:\Users\xxxx\anaconda3\Lib\site-packages\tensorflow\python).
Uninstall tensorflow using pip uninstall tensorflow and install pip install tf-nightly
This fix worked for me perfectly well.
I just got this error in CI builds with a requirements.txt that had
keras
tensorflow==2.9.1
and I assume the error was caused by pip install -r requirements.txt taking the recently released Keras 2.10 version, which probably assumes it's running next to TensorFlow 2.10, and that the minor mismatch led to this import error.

Fail to import MPLClassifier from SKlearn

I am trying to run MPL Neural Network using the scikit-learn library running on Jupyter Notebook. However, I have been trying to import the MPLClassifier but failed. I also have tried solution from here, SKlearn import MLPClassifier fails. I followed the steps and installed everything but could not import the module from SKlearn which are,
Installed the SKlearn using pip install scikit-neuralnetwork
Installed the mingw package using conda install mingw libpython and conda install -c free mingw, as the package is not available when using https://jmeubank.github.io/tdm-gcc/
Checked its availability using conda list
It is giving the following error,
cannot import name 'MPLClassifier' from 'sklearn.neural_network'
May I get help on other alternatives to import the module?

Importing imblearn in Jupyter is not working

I have installed imblearn using pip in command in command line and I'm able to import imblearn in python console. but when i use import imblearn in jupyter i'm getting error "ModuleNotFoundError: No module named 'imblearn'".
I know there are many answers in stackoverflow but nothing has worked. Thats the reason i'm posting new question.
I tired differnt option like.
installing !pip install imblearn in jupyter itself and restarted the kernel.
and updating sklearn in jupter.
Please let me know if any other way is there to solve this issue or any other details is required.

No module named 'bindsnet.network'

I am going to use Bindsnet for Spiking Neural Network and I have imported it using
! pip install bindsnet in jupyter notebook.
and My Python's version is 3.6.
when I run:
from bindsnet.network import Network
It returns below error message:
ModuleNotFoundError: No module named 'bindsnet.network'
Can you please let me know how to solve this?
It turned out that using pip install was not successful so I changed the code for installation to :
!pip install bindsnet --ignore-installed
and now I can run from bindsnet.network import Network with no error.

Python crashes when I import tensorflow

When I try to import tensorflow my python crashes. I tried uninstalling it and installing it again, but It isn't still working. Here is a picture of the command prompt when I try to import it.
I'm not too sure what the error is here.
try to pip list to see all packages
if no tensorflow seen then just pip install tensorflow
or print dir(tensorflow) to see functions
It seems you aren't executing anything but just importing the module.

Categories