Code is running properly in local windows machine but gives error while importing spacy.training in collab
what can be the problem?
from spacy.training import Example
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ebc5aa3cff21> in <module>()
3 from spacy.util import minibatch, compounding
4 from pathlib import Path
----> 5 from spacy.training import Example
6 # TRAINING THE MODEL
7 with nlp.disable_pipes(*unaffected_pipes):
ModuleNotFoundError: No module named 'spacy.training'
I believe You have spacy 2 on your colab.
You need to import spacy with all the modules again on colab.
It is independent from Windows spacy.
You can check your version of spacy and update it using below instructions:
Run this command on your Jupyter cell:
!pip show spacy
OR
spacy.__version__
Once you check the version, you can update to a latest version by:
!pip install -U spacy
Once, you get spacy 3 your problem will be resolved.
Example was introduced in spacy version 3.
Link to Example :
https://spacy.io/api/example#_title
Make sure to Restart Runtime from the menu bar in colab.
Related
I wrote following codes on a new google collabs notebook:
!pip install --quiet --upgrade tensorflow-federated-nightly
import tensorflow as tf
import tensorflow_federated as tff
And I got these error messages while importing tensorflow_federeated:
/usr/local/lib/python3.7/dist-packages/keras/api/_v1/keras/experimental/__init__.py in <module>()
8 from keras.feature_column.sequence_feature_column import SequenceFeatures
9 from keras.layers.rnn.lstm_v1 import PeepholeLSTMCell
---> 10 from keras.optimizers.learning_rate_schedule import CosineDecay
11 from keras.optimizers.learning_rate_schedule import CosineDecayRestarts
12 from keras.premade_models.linear import LinearModel
ModuleNotFoundError: No module named 'keras.optimizers.learning_rate_schedule'; 'keras.optimizers' is not a package
These errors seem to be spawning from the modules installed on the colabs itself, instead of my code.
Any idea on what can be done to fix this?
Collab Defaults to 3.7 according to a similar problem But although the solution to upgrade to 3.9 did indeed upgrade to python 3.9, TFF still didn't work for me, even when I installed locally. So, find a different path.
I'm getting the following error when importing StanzaLanguage from spacy_stanza:
ImportError Traceback (most recent call last)
in ()
4 import stanza
5 stanza.download('es')
----> 6 from spacy_stanza import StanzaLanguage
7
8
ImportError: cannot import name 'StanzaLanguage' from 'spacy_stanza' (/usr/local/lib/python3.7/dist-packages/spacy_stanza/init.py)
I think you've installed newest spacy-stanza but you're trying to use it with older spaCy:
As of v1.0.0 spacy-stanza is only compatible with spaCy v3.x. For spaCy v2, install v0.2.x
pip install "spacy-stanza<0.3.0"
Take a look what are the differences in Usage & Examples between them:
https://github.com/explosion/spacy-stanza vs https://github.com/explosion/spacy-stanza/tree/v0.2.x#-usage--examples
Hi I have been trying to install twython for Jupyter Notebook. I have proved through the python repl that it is universally installed throughout my laptop. But it still won't appear on Jupyter Notebook. Looking for help trying to figure out it is found in a spot that it can be found by my Anaconda 3 Jupyter Notebook.
Context: Homework assignment trying to mine twitter for tweets
Here is the errors I am receiving and I am running Mac OS
/Users/name/twitter/__init__.py:22: UserWarning: The twython library has not been installed. Some functionality from the twitter package will not be available.
"The twython library has not been installed. "
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-38297a1141e0> in <module>
----> 1 import twitter
2 import twython
3 #---------------------------------------------
4 # Define a Function to Login Twitter API
5 def oauth_login():
~/twitter/__init__.py in <module>
34
35
---> 36 from nltk.twitter.common import json2csv
ModuleNotFoundError: No module named 'nltk.twitter
Have you installed nltk package?
If not, do it:
pip3 install -U nltk
then run python3
inside python3 command line, run:
import nltk
nltk.download()
after the download, restart jupyter, and run your code again.
I am on windows using Anaconda with python 3.6, I have installed keras by:
conda install -c conda-forge keras
and whene i try this code
from keras.models import Graph
I get this error message:
ImportError Traceback (most recent call last)
<ipython-input-4-74d2d1fd7bad> in <module>()
----> 1 from keras.models import Graph
ImportError: cannot import name 'Graph'
This is not a Python issue. This is because the latest version of keras has removed Graph module from models. You can surely check the documentation.
If you check this Github issue (Why Keras remove graph model?), you can use the following line of code:
from .legacy.models import Graph
However, it is suggested to use functional API instead. Please check The Functional API
Following the tutorial:
http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/#comment-419896
Using these files:
https://github.com/fchollet/deep-learning-models
I get 2 separate errors depending on how I execute:
Running in PyCharm:
Using TensorFlow backend.
usage: test_imagenet.py [-h] -i IMAGE
test_imagenet.py: error: the following arguments are required: -i/--image
Running in cmd line:
C:\Users\AppData\Local\Programs\Python\Python35\Scripts>python deep-learning-models/test_imagenet.py --image deep-learning-models/images/dog.jpg
Traceback (most recent call last):
File "deep-learning-models/test_imagenet.py", line 2, in <module>
from keras.preprocessing import image as image_utils
ImportError: No module named keras.preprocessing
How do I resolve?
Its best if you solve this problem outside running the above script... Here is what you can try in your command line environment to make sure it works outside your script:
>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'1.2.1'
>>> keras.preprocessing
<module 'keras.preprocessing' from '/usr/local/lib/python2.7/dist-packages/keras/preprocessing/__init__.pyc'>
>>> from keras.preprocessing import image as image_utils
>>>
Make sure you have latest version of keras installed. If you get above working then it could be the environment issue where above script is not able to find the keras package. However if above does not work or work partially you would need to install keras again by removing it first..
$ pip install keras --user
Every dependency in a python project need to be installed using pip or easy_install or from the source code. You will have to install the keras module as mentioned here.
This happened to me. It turned out I was working in a pyvenv which wasn't activated. Just run source bin/activate on Linux/Mac or Scripts\activate.bat on Windows
from keras.models import Sequential
from keras import legacy_tf_layer
from keras.preprocessing import image as image_utils
from keras.preprcessing.text import Toknizer
import pandas as pd
from sklearn.model_selection import train_test_spli