AttributeError: module 'torch.utils' has no attribute 'data' - python

I am trying to run my PyTorch code on a Ubuntu server, it works well on my own computer, but it failed to run on the server.
Is this because of something related to PyTorch version?
This problem seems typical but yet no solutions work.
Traceback (most recent call last):
File "train.py", line 12, in <module>
from data_manager import *
File "/data1/lijun/cross_modal_reid_bigma/transformer/data_manager.py", line 7, in <module>
from util.data_loader import DataLoader
File "/data1/lijun/cross_modal_reid_bigma/transformer/util/data_loader.py", line 6, in <module>
from torchtext.legacy.data import Field, BucketIterator
File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/__init__.py", line 3, in <module>
from . import datasets
File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/datasets/__init__.py", line 2, in <module>
from .ag_news import AG_NEWS
File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/datasets/ag_news.py", line 2, in <module>
from torchtext.data.datasets_utils import _RawTextIterableDataset
File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/data/datasets_utils.py", line 205, in <module>
class _RawTextIterableDataset(torch.utils.data.IterableDataset):
AttributeError: module 'torch.utils' has no attribute 'data'

it worked for me...please make sure that you are using 1.7 + pytorch version

When use Pytorch 1.1, You can simply solve this problem by add this import:
import torch.utils.data
And Pytorch 1.7+ has this bug fixed.

Related

collection.Mutablemapping Error in pyrebase Import

I have installed pyrebase library and tried importing it Like
import pyrebase
It gives following Error and i dont know how to fix it!
Traceback (most recent call last):
File "fire.py", line 1, in <module>
import pyrebase
File "env\lib\site-packages\pyrebase\__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "env\lib\site-packages\pyrebase\pyrebase.py", line 1, in <module>
import requests
File "env\lib\site-packages\requests\__init__.py", line 63, in <module>
from . import utils
File "env\lib\site-packages\requests\utils.py", line 27, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "env\lib\site-packages\requests\cookies.py", line 172, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Tried following some stack overflow advice but those wewe not specific.
This happens because pyrebase uses a deprecated collections module. Fixing this issue is possible but it leads to a chain of issues, I would recommend you to used pyrebase4 instead.

ImportError: cannot import name 'KernelProvisionerBase' from 'jupyter_client.provisioning'

Very messy tonight. It was working fine before until I tried to upgrade tensorflow to 2.6. it failed, then all other packages also broke. for example, I cannot launch jupypter notebook. I did try to upgrade it by using conda update jupyter. Thanks for your help.
(forecast) C:\Python_Sync\ML timeseries>jupyter notebook
Traceback (most recent call last):
File "C:\Users\test\miniconda3\envs\forecast\Scripts\jupyter-notebook-script.py", line 5, in <module>
from notebook.notebookapp import main
File "C:\Users\test\miniconda3\envs\forecast\lib\site-packages\notebook\notebookapp.py", line 78, in <module>
from .services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager
File "C:\Users\test\miniconda3\envs\forecast\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 18, in <module>
from jupyter_client.session import Session
File "C:\Users\test\miniconda3\envs\forecast\lib\site-packages\jupyter_client\__init__.py", line 11, in <module>
from .manager import AsyncKernelManager # noqa
File "C:\Users\test\miniconda3\envs\forecast\lib\site-packages\jupyter_client\manager.py", line 29, in <module>
from .provisioning import KernelProvisionerBase
ImportError: cannot import name 'KernelProvisionerBase' from 'jupyter_client.provisioning' (unknown location)
ok, i ended up solving this after:
conda update --all

functools has no attribute lru_cache

I'm using Python 3.7 on my Windows
This error occurs while running every code:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import nltk
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\__init__.py", line 99, in <module>
from nltk.internals import config_java
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\internals.py", line 11, in <module>
import subprocess
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 50, in <module>
import signal
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\signal.py", line 3, in <module>
from functools import wraps as _wraps
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\functools.py", line 21, in <module>
from collections import namedtuple
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\collections\__init__.py", line 22, in <module>
from keyword import iskeyword as _iskeyword
File "C:\Users\HP\Desktop\tweepy\keyword.py", line 1, in <module>
import re
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
How to fix it?
It looks like someone published a functools package on pypi, so if you had run:
# don't run this!
pip install functools
You may have accidentally installed that package. If you encounter this error, I would:
pip uninstall functools
To make sure that the functools you are using are the base package functools.
(I ended up here because I attempted to use functools.cache, which seems to only be present in Python 3.8, not earlier.)
I had the same error recently and it was because I had a file called functools.py in my project. Renaming it fixed the issue.

Resolve AttributeError: module 'pandas' has no attribute 'core' using command-prompt or pycharm

I am struggling because of the error
AttributeError: module 'pandas' has no attribute 'core'
since quite a long time please refer the output of "import pandas" below. I have searched for this error on the net and searched at many places tried many things but was unable to resolve it. The problem was the solutions provided were more realted to other operating systems like Mac and Linux while I am using Windows 7 Professional.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\api.py", line 10, in <module>
from pandas.core.groupby.groupby import Grouper
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\groupby\__init__.py", line 2, in <module>
from pandas.core.groupby.groupby import (
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\groupby\groupby.py", line 49, in <module>
from pandas.core.frame import DataFrame
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\frame.py", line 74, in <module>
from pandas.core.series import Series
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\series.py", line 66, in <module>
import pandas.core.ops as ops
AttributeError: module 'pandas' has no attribute 'core'
Please do ask if you need any other details. I will be really gratified if you help me through this.
Thankyou
P.S if you can suggest a solution which does not use internet using terminal such as in case of "pip install pandas" as the company's network access is restricted. So, I installed all the dependencies of pandas through whl files which are downloadable through the access the company has provided.
Edit: The first time I execute pandas it shows and rest it shows the error shown above
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\api.py", line 10, in <module>
from pandas.core.groupby.groupby import Grouper
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\groupby\__init__.py", line 2, in <module>
from pandas.core.groupby.groupby import (
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\groupby\groupby.py", line 49, in <module>
from pandas.core.frame import DataFrame
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\frame.py", line 74, in <module>
from pandas.core.series import Series
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\series.py", line 3978, in <module>
Series._add_series_or_dataframe_operations()
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\generic.py", line 8891, in _add_series_or_dataframe_operations
from pandas.core import window as rwindow
File "C:\Users\IshanL\PycharmProjects\Project1\venv\lib\site-packages\pandas\core\window.py", line 36, in <module>
import pandas._libs.window as _window
ImportError: DLL load failed: The specified module could not be found.
conda upgrade --all
Upgrade your library and restart your notebook.This will do the work.

Installing llvmpy on OSX

I've been following this guide. Unfortunately I don't think llvmpy is being installed properly (here is the output from python).
>>> import numba
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/numba/__init__.py", line 5, in <module>
from . import testing, decorators
File "/Library/Python/2.7/site-packages/numba/decorators.py", line 7, in <module>
from numba.targets import registry
File "/Library/Python/2.7/site-packages/numba/targets/registry.py", line 3, in <module>
from numba.targets import cpu
File "/Library/Python/2.7/site-packages/numba/targets/cpu.py", line 4, in <module>
import llvm.core as lc
File "llvm/__init__.py", line 6, in <module>
from llvmpy import extra
File "llvmpy/extra.py", line 5, in <module>
from llvmpy import capsule
File "llvmpy/capsule.py", line 4, in <module>
from llvmpy._capsule import (unwrap, has_ownership, downcast, wrap,
ImportError: No module named _capsule
Doing python -c "import llvm" gives me the same error as above ("No module named _capsule"). Any ideas? I am not getting errors while installing llvm,llvmpy or numba, but it is pretty clear that llvmpy isn't getting installed properly
I forgot to answer this. I solved the problem as the underlying issue was an Apple-release (see this answer to a similar'ish question).
TLDR:
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
And then follow the guide given here

Categories

Resources