ImportError Traceback (most recent call last)
in
from bidaf.models import BidirectionalAttentionFlow
bidaf_model = BidirectionalAttentionFlow(400)
keras_model = bidaf_model.model
~\AppData\Roaming\Python\Python38\site-packages\bidaf\models_init_.py in
from bidaf.models import BidirectionalAttentionFlow
~\AppData\Roaming\Python\Python38\site-packages\bidaf\models\bidaf.py in
ImportError: cannot import name 'Adadelta' from 'keras.optimizers' (C:\Users\vishd\AppData\Roaming\Python\Python38\site-packages\keras\optimizers.py)
I have been trying to recreate the Keras-bidaf model in my python notebook and running this code in python from bidaf. models import BidirectionalAttentionFlow which keeps giving me the above error and saying Adadelta can't be imported from Keras. I have tried so many options to solve it but no luck.
I am stuck here. Any suggestions and ideas are highly appreciated.
Related
I was just getting started with PyCharm and python for statistics.
And I got this error:
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Full traceback looks like this:
Traceback (most recent call last):
File "/home/tetiana/forVScode/python/first/first_try.py", line 1, in
from scipy import stats
File "/usr/lib/python3/dist-packages/scipy/stats/init.py", line 379, in
from .stats import *
File "/usr/lib/python3/dist-packages/scipy/stats/stats.py", line 180, in
import scipy.special as special
File "/usr/lib/python3/dist-packages/scipy/special/init.py", line 643, in
from .basic import *
File "/usr/lib/python3/dist-packages/scipy/special/basic.py", line 19, in
from . import orthogonal
File "/usr/lib/python3/dist-packages/scipy/special/orthogonal.py", line 81, in
from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/init.py)
Process finished with exit code 1
How can I fix it?
Here is my code:
from scipy import stats
import pandas as pd
state = pd.read_csv('state_murder_rate_test_table.csv')
state['Population'].mean()
stats.trim_mean(state['Population'], 0.1)
state['Population'].median()
I checked whether the Python versions in os and in the project match and they are. I have python 3.8.10 and my os is Ubuntu 20.04
Referring to the current numpy documentation, there exists no type called numpy.int that you can import. I believe that the type you wanna import is numpy.integer or numpy.int_.
The code you provided does not have any statement like: from numpy import int. If you could provide a full traceback error, it'll be easier to see where the error stems from.
I hope this answer will be somewhat useful.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22516\254480426.py in <module>
2 import matplotlib.pyplot as plt
3 from mpl_toolkits.mplot3d import Axes3D, art3d # NOQA
----> 4 from matplotlib.cbook import _backports
5 from collections import defaultdict
6 import types
ImportError: cannot import name '_backports' from 'matplotlib.cbook' (C:\Users\saidt\anaconda3\envs\tensorflow\lib\site-packages\matplotlib\cbook\__init__.py)
I cannot solve this problem. I tried several ways advised on other posts (uninstalled, reinstalled, changed the version of matplotlib) but still have this issue. I even checked matplotlib.cbook (https://matplotlib.org/stable/api/cbook_api.html) but there is no _backports. I wonder where to find the solution. If someone could help, I would really appreciate it.
When I import mlxtend.frequent_patterns, the function fpgrowth and fpmax are not there. However, they are there if I use Jupyter Notebook in Anaconda Navigator.
Anyone know why Colab will not import?
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori, fpmax, fpgrowth
ImportError
Traceback (most recent call last)
in ()
2
3 from mlxtend.preprocessing import TransactionEncoder
----> 4 from mlxtend.frequent_patterns import apriori, fpmax, fpgrowth
5
6
ImportError: cannot import name 'fpmax' from 'mlxtend.frequent_patterns' (/usr/local/lib/python3.7/dist-packages/mlxtend/frequent_patterns/init.py)
I had the same issue just now. The first solution suggested was to pip the package using this in a code cell:
! pip install mlxtend
However, while that helped with me using apriori, it did not help with fpgrowth. Then, after about three hours, I found a solution. Again, in a code cell, run this:
%pip install mlxtend --upgrade
I'm not sure what the % does that the ! does not.
So I installed the latest version of transformers on Google Colab
!pip install transformers
When trying to invoke the conversion file using
!python /usr/local/lib/python3.6/dist-packages/transformers/convert_pytorch_checkpoint_to_tf2.py .py --help
Or trying to use
from transformers.file_utils import hf_bucket_url. // works
from transformers.convert_pytorch_checkpoint_to_tf2 import *. // fails
convert_pytorch_checkpoint_to_tf("gpt2", pytorch_file, config_file, tf_file).
I get this error
ImportError Traceback (most recent call last)
<ipython-input-3-dadaf83ecea0> in <module>()
1 from transformers.file_utils import hf_bucket_url
----> 2 from transformers.convert_pytorch_checkpoint_to_tf2 import *
3
4 convert_pytorch_checkpoint_to_tf("gpt2", pytorch_file, config_file, tf_file)
/usr/local/lib/python3.6/dist-packages/transformers/convert_pytorch_checkpoint_to_tf2.py in <module>()
20 import os
21
---> 22 from transformers import (
23 ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
24 BERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
ImportError: cannot import name 'hf_bucket_url'
What's going on?
It turns out to be a bug. This PR solves the issue by importing the function hf_bucket_url properly.
I get an errr when using scipy.stats. in a script after importing scipy.
AttributeError: 'module' object has no attribute 'stats'
Within script editor I can click on stats after typing scipy. from the pulldown menu,
within python console I can not select python.stats from the pulldown menu, it's not there.
I'm using pandas 2.7 and SciPy 0.13.0
Why is that?
Any known issues?
expanding on my comment (to have a listed answer).
Scipy, as many other large packages, doesn't import all modules automatically. If we want to use the subpackages of scipy, then we need to import them directly.
However, some scipy subpackages load other scipy subpackages, so for example importing scipy.stats also imports a large number of the other packages. But I never rely on this to have the subpackage available in the namespace.
In many packages that use scipy, the preferred pattern is to import the subpackages to have them available by their names, for example:
>>> from scipy import stats, optimize, interpolate
>>> import scipy
>>> scipy.stats
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'stats'
>>> scipy.optimize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'optimize'
>>> import scipy.stats
>>> scipy.optimize
<module 'scipy.optimize' from 'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'>
This is expected. Most of the subpackages are not imported when you just do import scipy. There are a lot of them, with a lot of heavy extension modules that take time to load. You should always explicitly import the subpackages that you want to use.
https://github.com/scipy/scipy/issues/13618
if you import scipy alone like this:
import scipy
then you use:
scipy.stats
You will get:
AttributeError: module 'scipy' has no attribute 'stats'
You have to import like this:
import scipy.stats
or
import scipy
import stats