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.
Related
---------------------------------------------------------------------------
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.
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.
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 am attempting run in Jupyter
import pandas as pd
import matplotlib.pyplot as plt # plotting
import numpy as np # dense matrices
from scipy.sparse import csr_matrix # sparse matrices
%matplotlib inline
However when loading the dataset with
wiki = pd.read_csv('people_wiki.csv')
# add id column
wiki['id'] = range(0, len(wiki))
wiki.head(10)
the following error persists
NameError Traceback (most recent call last)
<ipython-input-1-56330c326580> in <module>()
----> 1 wiki = pd.read_csv('people_wiki.csv')
2 # add id column
3 wiki['id'] = range(0, len(wiki))
4 wiki.head(10)
NameError: name 'pd' is not defined
Any suggestions appreciated
Select Restart & Clear Output and run the cells again from the beginning.
I had the same issue, and as Ivan suggested in the comment, this resolved it.
If you came here from a duplicate, notice also that your code needs to contain
import pandas as pd
in the first place. If you are using a notebook like Jupyter and it's already there, or if you just added it, you probably need to re-evaluate the cell, as suggested in the currently top-voted answer by martin-martin.
python version will need 3.6 above, I think you have been use the python 2.7. Please select from top right for your python env version.
Be sure to load / import Pandas first
When stepping through the Anaconda Navigator demo, I found that pressing "play" on the first line before inputting the second line resolved the issue.
I am new to iPython/Jupyter. Python skills limited, but learning. I am trying to import numpy as np and get the following:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4ee716103900> in <module>()
----> 1 import numpy as np
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/__init__.py in <module>()
166 return loader(*packages, **options)
167
--> 168 from . import add_newdocs
169 __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
170
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
6 from numpy.version import version as __version__
7
----> 8 from .type_check import *
9 from .index_tricks import *
10 from .function_base import *
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/lib/type_check.py in <module>()
9 'common_type']
10
---> 11 import numpy.core.numeric as _nx
12 from numpy.core.numeric import asarray, asanyarray, array, isnan, \
13 obj2sctype, zeros
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/__init__.py in <module>()
4 from numpy.version import version as __version__
5
----> 6 from . import multiarray
7 from . import umath
8 from . import _internal # for freeze programs
ImportError: dlopen(/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/multiarray.so: mach-o, but wrong architecture
I have several python installs on my Mac, which has Yosemite, including Canopy and Anaconda. I want my Jupyter notebook to use the Anaconda install including all the modules, libraries, etc. associated with it. It seems however that jupyter is targeting Canopy instead. Thus, I think my problem might stem from the wrong linkage.
QUESTION 1: Does my conclusion hold water? If not, what might I be missing?
QUESTION 2: How can I direct/link jupyter with Anaconda and not with Canopy so that I import everything from anaconda only?
Thanks for everyone's help!
You can either set the PATH to execute python commands from the ~/anaconda/bin directory by prepending it to your .bah_profile by running the following command.
export PATH="/Users/jmmiii/anaconda/bin:$PATH"
OR, you can create an alias for the command by editing your ~/.bash_profile and adding:
alias jupyter-notebook="/Users/jmmiii/anaconda/bin/jupyter-notebook"