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.
Related
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.
I am a beginner and I just started with machine learning. I am trying to import classes like imputer from sklearn but i am unable to do it.
from sklearn.preprocessing import Imputer,LabelEncoder,OneHotEncoder,StandardScaler
ImportError: cannot import name 'version' from
'sklearn.externals.joblib'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib__init__.py)
I had the same problem.
I have replaced
from sklearn.externals import joblib
with
import joblib
and it works fine in Python 3.7.2
I believe there was an update on Scikit-learn that render that import unusable.
I had my local installation to be version 0.20.3 and this import is pefectly working. But on my server I have installation 0.23.1 and this error pop up. Something must be chaging in the new version.
For my case, use import joblib fix the problem. In your case it seems more complicated. This sounds very much likeky to be caused if you have more than one Scikit-learn version installed on your system. You need to uninstall all of them and do a clean install of sklearn.
The problem sometimes happens due to the version. This may help:
If you has written like this
from sklearn.externals import joblib
Modify it as this:
import joblib
Try
python -m pip install sklearn --upgrade
and
python -m pip install joblib --upgrade
and then, use this :
import joblib
Good luck.
import joblib
This works for me. Actually I was having that kinda challenge
When I try to run
import sklearn.linear_model
I get an error
~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\lib\site-packages\sklearn\linear_model\least_angle.py in <module>
21 from .base import LinearModel
22 from ..base import RegressorMixin
---> 23 from ..utils import arrayfuncs, as_float_array, check_X_y, deprecated
24 from ..model_selection import check_cv
25 from ..exceptions import ConvergenceWarning
ImportError: DLL load failed: The specified module could not be found.
I did some digging, and it looks like I don't have the as_float_array package
ModuleNotFoundError: No module named 'sklearn.utils.as_float_array'
I tried reinstalling, but no change. What's going on?
This appears to be very specific to your IDE/environment. It will be easier to solve if you provide more details. You can try the following:
Are you able to run the following code?
import sklearn
print(sklearn.__version__)
Can you list the packages installed and see if sklearn is there?
pip3 list
Do you see the same problem in Anaconda alone, or when you run this in command line?
Edit: possible solution
This looks like an access issue.
If you are on Windows OS, remove Anaconda & re-install it in a common folder, instead of under admin controlled folders (for example C:\anaconda, instead of under C:\Program Files).
Launch a new terminal from Anaconda Navigator -> Environments, then run this code.
Usually a conda install solves the problem:
conda install -c anaconda scikit-learn
It happened to me, for numpy
When i try to import WordEmbeddingSimilarityIndex, it's giving me the following error:
>> from gensim.models import WordEmbeddingSimilarityIndex
ImportError: cannot import name 'WordEmbeddingSimilarityIndex
The same issue occurs for SparseTermSimilarityMatrix function:
>> from gensim.similarities import SparseTermSimilarityMatrix
ImportError: cannot import name 'SparseTermSimilarityMatrix
Note: I have installed and imported gensim, gensim.models and gensim.similarities. But still it's giving me the ImportError while importing the above mentioned functions.
Can you tell me what I am doing wrong, please?
Fix is change "models" to "similarities"
from gensim.similarities import WordEmbeddingSimilarityIndex
it works in gensim 4.0.1
Try to check the version of gensim that you are using. Usually, the older versions of gensim cause this issue.
from gensim.models import WordEmbeddingSimilarityIndex
print(gensim.__version__)
if the gensim version is 3.6.x or older update it to 3.7.x or latest version by running the below command. Once you update gensim version should get rid of this issue.
pip install --upgrade gensim
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