Implementing word2vec in python3 WITHOUT gensim - python-3.x

We're running into a lot of problems installing word2vec within python3. We just keep getting a standard error that python can't find the package it's looking for.
Competition-Repo/agents$ python3
Python 3.4.3 [GCC 4.8.4] on linux
import word2vec
Traceback (most recent call last):
File "", line 1, in ImportError: No module named 'word2vec'
Most everything I've found has either someone else's implementation of word2vec within python3, or is accessed through Gensim. The pip-install for python2 imports flawlessly, now we need to set up the same thing for python3.
Thanks!
-Ben

I just installed the product from Github site without incident on Python 3.4 but Win7Pro. It imports but who knows after that, right?
It comes with a setup.py. Being an inveterate experimenter I tried that, contrary to instructions. It failed.
At least this is easy to try, assuming you haven't already.

How exactly are you importing in python2?
With gensim, you can either import with -
from gensim.models import Word2Vec
or with -
from gensim.models import word2vec
The former is for the class Word2Vec and the latter for the module.
There is a tutorial here for getting started

The way we were able to install it was through:
sudo pip3 install cython
sudo pip3 install word2vec
Turned out to be a lot easier than I had thought..

Related

Tensorflow installed can't be imported

I'm trying to import tensorflow. But even after installing it, it doesn't seem to be recognized.
>conda create -n tf tensorflow
>conda activate tf
(tf)>pip install --ignore-installed --upgrade tensorflow==1.15 --user
...
Successfully installed absl-py-0.9.0 astor-0.8.1 gast-0.2.2 google-pasta-0.2.0 grpcio-1.28.1 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 numpy-1.18.2 opt-einsum-3.2.0 protobuf-3.11.3 setuptools-46.1.3 six-1.14.0 tensorboard-1.15.0 tensorflow-1.15.0 tensorflow-estimator-1.15.1 termcolor-1.1.0 werkzeug-1.0.1 wheel-0.34.2 wrapt-1.12.1
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>python3 app.py
Traceback (most recent call last):
File "app.py", line 4, in <module>
from tensorflow.keras.callbacks import ModelCheckpoint
ModuleNotFoundError: No module named 'tensorflow'
Python3 is there:
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>where python3
C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\python3.exe
It's not the one I should be using, isn't it?
What version of Python are you running? In order to both successfully import and run the Tensorflow module, you must have the 64 bit version of Python installed. If you are using the latest version of Python, which to the best of my knowledge is 3.8.2, completely uninstall that version of Python, and downgrade to the latest Python version with 64 bit support.
If you follow the output of pip --version to find where your anaconda files are located, you can find the anaconda python executable, usually about two directory levels higher (if pip is in C:\example\anaconda\lib\site-packages, then python is probably in C:\example\anaconda) and use a full path to that python executable to run the file like C:\example\anaconda\python app.py. Or you could update your path environment variable to replace C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\ with the directory containing the anaconda python executable
I've had this same exact issue (but on macOS) several times before I realized what was wrong, and I've seen several others have this issue too. I wish there was a way Python could somehow better regulate this to make sure the default executables for pip and python are always in sync

Exception has occurred: ModuleNotFoundError No module named 'cv2'

I have code that requires: import cv2
but get the error message: Exception has occurred: ModuleNotFoundError
No module named 'cv2'
I have seen exactly the same question before, but all the suggestions fail. The question is 6 years old and hence am repeating it.
various failed suggestions:
conda install --channel https://conda.anaconda.org/menpo opencv3
conda install -c menpo opencv
I am using Windows 10 and have python 3.8.1 running.
I have removed cv2 from the code which works without error and resolves the issue.
The link here (at time of writing, version 4.1.2.3) describes the opencv-python package:
opencv-python link
With the following description of cv2 towards the bottom of the page:
It's easier for users to understand opencv-python than cv2 and it makes it easier to find the package with search engines. cv2 (old interface in old OpenCV versions was named as cv) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the import cv2.

Unable to import sklearn and statsmodels from Anaconda from windows 10 pro

I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here

sklearn.linear_model not found in TensorFlow Udacity course

I'm following the instructions of the Deep Learning course by Google with TensorFlow. Unfortunately I'm stuck with this workbook right now.
I work in the docker vm with all the assignment code loaded as described here.
When I do all the imports everything works except for following line:
from sklearn.linear_model import LogisticRegression
it throws the following error:
>>> from sklearn.linear_model import LogisticRegression
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn.linear_model
This SO answer sounds promising, but I did not find the source directory of sklearn.
Any help greatly aprreciated.
You can install and upgrade sklearn from the shell with pip. That may or may not be the problem - but at least you'll know its installed.
sudo pip install --upgrade scikit-learn
In your Jupyter notebook:
import pip
pip.main(['install', 'sklearn'])
Please take note that when you are writing your code, you'll import the sklearn package using import sklearn, but when installing the package it with, say, conda, you should do the following:
conda install scikit-learn

Scikit Learn import error: 'cross_val_predict' is not defined

I am trying to run some simple codes of scikit-learn in python, and while executing this, I encountered this error:
from sklearn.cross_validation import cross_val_predict
Traceback (most recent call last):
File "", line 1, in
from sklearn.cross_validation import cross_val_predict
ImportError: cannot import name cross_val_predict
I have downloaded scikit learn from this page: http://sourceforge.net/projects/scikit-learn/?source=typ_redirect and the other modules like sklearn.linear_model works well. It seems that I can also import successfully the module cross_validation.. I cannot understand!
Yes ! It seems works now ! In fact, instead of using the .exe files that I downloaded from internet (which turned out to be perhaps incompatible), I finally successed to install many modules by the standard "pip install". The only thing that I could not use "pip install" is the package "Scipy", so I had to replace it by a .exe file. Thank you for all your help !

Resources