AttributeError: 'module' object has no attribute 'version' Canopy - python

Hi I am going to preface this with I could just be really dumb so don't overlook that, but suddenly when opening canopy today I wasn't able to run one of my typical scripts with the error AttributeError: 'module' object has no attribute ' version' when trying to load pandas. From what I can gather it seems when bumpy is called through pandas it fails. I checked my working directory for files named numpy.py to see if I idiotically named a file numpy but failed to find such a file. I also attempted to uninstall and reinstall both numpy and pandas from the package manager in canopy. Any suggestions?
%run "/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py in <module>()
1 #import the modules you need
----> 2 import pandas as pd
3 import numpy as np
4 import plotly.plotly as py
5 import plotly.tools as tls
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy_compat import *
23
24 try:
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/compat/numpy_compat.py in <module>()
13
14 # numpy versioning
---> 15 _np_version = np.version.short_version
16 _np_version_under1p8 = LooseVersion(_np_version) < '1.8'
17 _np_version_under1p9 = LooseVersion(_np_version) < '1.9'
AttributeError: 'module' object has no attribute 'version'

Just had the same problem after downgrading Pandas and upgrading again to fix another issue. This is just a hack, but you could try this:
Open ...pandas/compat/numpy_compat.py and replace np.version.short_version with np._np_version
Hope that helps!

Related

importing dask_cuda results in parse_memory_limit error

I'm trying to import dask_cuda as the examples:
from dask_cuda import LocalCUDACluster
from dask.distributed import Client
But I receive the following error:
ImportError Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 from dask_cuda import LocalCUDACluster
File ~/miniconda3/lib/python3.8/site-packages/dask_cuda/__init__.py:5, in <module>
2 import dask.dataframe.shuffle
4 from ._version import get_versions
----> 5 from .cuda_worker import CUDAWorker
6 from .explicit_comms.dataframe.shuffle import get_rearrange_by_column_tasks_wrapper
7 from .local_cuda_cluster import LocalCUDACluster
File ~/miniconda3/lib/python3.8/site-packages/dask_cuda/cuda_worker.py:19, in <module>
14 from distributed.proctitle import (
15 enable_proctitle_on_children,
16 enable_proctitle_on_current,
17 )
18 from distributed.utils import parse_bytes
---> 19 from distributed.worker import parse_memory_limit
21 from .device_host_file import DeviceHostFile
22 from .initialize import initialize
ImportError: cannot import name 'parse_memory_limit' from 'distributed.worker' (/home/shambakey1/miniconda3/lib/python3.8/site-packages/distributed/worker.py)
I googled this error, but couldn't find anything related to it. I thought it was a DASK problem, so I re-tried with only from dask.distributed import Client, and it worked. So, I guess this error is related to dask_cuda, but I don't know how.
The version I have are:
dask-cuda -> 22.6.0
dask -> 2021.12.0
distributed -> 2021.12.0
Ubuntu 20.04
Regards
Your dask version is rather old, the parse_memory_limit was added fairly recently in 2022, see this PR.
I would recommend not pinning dask and let conda find the most suitable version. If that's not an option, then dask=2022.7.0 works for me with dask-cuda=2022.6.0.

'FileDataset' object has no attribute 'DoseGrid'

I have been trying to use the dicompyler-core to put together two dose grids from two different dose dicoms.
import pydicom
import numpy as np
import os
import glob
from dicompylercore import dicomparser, dvh, dvhcalc
from dicompylercore import dose
I keep receiving this error while trying to import dose
ImportError Traceback (most recent call last)
<ipython-input-120-6605335fa321> in <module>
5 import glob
6 from dicompylercore import dicomparser, dvh, dvhcalc
----> 7 from dicompylercore import dose
ImportError: cannot import name 'dose' from 'dicompylercore'
Because of this import error, I think that is why there is no attribute to be found when I try and add the two dose grids together
dose1 = dicomparser.DicomParser("RD.CW.dcm")
dose2 = dicomparser.DicomParser("RD.CCW.dcm")
grid_1 = dose.DoseGrid()
grid_2 = dose.DoseGrid()
grid_sum = grid_1 + grid_2
grid_sum.save_dcm("grid_sum.dcm")
It gives me this error
~\Anaconda3\lib\site-packages\pydicom\dataset.py in __getattr__(self, name)
550 if tag is None: # `name` isn't a DICOM element keyword
551 # Try the base class attribute getter (fix for issue 332)
--> 552 return super(Dataset, self).__getattribute__(name)
553 tag = Tag(tag)
554 if tag not in self._dict: # DICOM DataElement not in the Dataset
AttributeError: 'FileDataset' object has no attribute 'DoseGrid'
I am new to working with dicom files and with dicompylercore. I am unsure if this is related to the dicom files I am working itself or if there is some issue with the dicomplyercore package itself. Are there any suggestions on what I could do to fix this?
The dose module has been added to dicompylercore after the last PyPi release, so you have to install the version from GitHub, if you want to use it:
pip install git+https://github.com/dicompyler/dicompyler-core
I'm not sure how stable this version is, but you can ask about the next release on the development site.

Torchtext on Colab: Cannot import name 'dtype_to_attr'

having trouble importing torchtext.data or .datasets with the following error on Google Colab. Tried to 1/ upgrade torch to 1.7, 2/ upgrade torchtext to 0.4 or 0.5 or latest as per some posts. But none seem to help.
Wondering if you have any insights here? Trying to import to embed / tokenize word sequences.
ImportError Traceback (most recent call last)
in ()
1 # For data loading.
----> 2 from torchtext import data, datasets
2 frames
/usr/local/lib/python3.6/dist-packages/torchtext/data/field.py in ()
8 from .dataset import Dataset
9 from .pipeline import Pipeline
---> 10 from .utils import get_tokenizer, dtype_to_attr, is_tokenizer_serializable
11 from ..vocab import Vocab, SubwordVocab
12
ImportError: cannot import name 'dtype_to_attr'

import gensim and got an TypeError: expected bytes, Descriptor found

I try import gensim library in python3.
all of the libraries are last version.
in first import got an TypeError: expected bytes, Descriptor found
and in second import got an this error:
import gensim
> AttributeError Traceback (most recent call last)
<ipython-input-7-e70e92d32c6e> in <module>
----> 1 import gensim
~\Anaconda3\lib\site-packages\gensim\__init__.py in <module>
3 """
4
~\Anaconda3\lib\site-packages\smart_open\transport.py in <module>
20 NO_SCHEME = ''
21
---> 22 _REGISTRY = {NO_SCHEME: smart_open.local_file}
23
24
AttributeError: module 'smart_open' has no attribute 'local_file'
I fixed this problem by this steps:
pip install smart-open==1.9.0
pip install gensim==3.4.0
this worked for me

Importing Classes & Variables in Python 2.7

Hi I'm having trouble importing classes and variables into python files from other python files. Functions work fine.
As a test, I set up file1 with a function, a class, an assigned instance of the class, and a random variable. I then used various methods in file2:
1.
import file1
2.
from file1 import *
error: 'name not defined'
3.
from file1 import variable,class,instance,etc
error: cannot import name Class
4+. And then doing some other things...
creating a init.py file
or then trying to set directory:
import os
os.chdir("/Users/mardersteina/Documents")
Not sure what I'm doing wrong. Function imports fine, but can't figure this one out with the classes and variables no matter what I'm looking up.
Untitled7:
def happy():
print "yo!"
class Tap(object):
def __init__(self,level):
self.level = level
level4 = Tap(4)
x = 14
Untitled9:
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
1 import Untitled7
2
----> 3 print Untitled7.x
4 """
5 from Untitled7 import Tap
AttributeError: 'module' object has no attribute 'x'
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
4 print Untitled7.x
5 """
----> 6 from Untitled7 import Tap
7
8 print Tap(4).level
ImportError: cannot import name Tap
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
11 from Untitled7 import *
12
---> 13 print level4.level
NameError: name 'level4' is not defined
I can see that you are running the file from an open console .
Most probably the issue is that you had imported the Untitled7.py previously when it only had one function . When you do that Python caches the module in sys.modules .
So if you try to import it in same session again, you would get the cached version from sys.modules , and that would be the reason any changes to the Untitled7 you did after importing it once are not visible.
To fix this issue, you can reload the module -
In Python 3.x , use importlib.reload() to reload the module (to take in new changes) , Example -
import importlib
importlib.reload(Untitled7)
In Python 2.x , use reload() method -
reload(Untitled7)
Or you can also close the python terminal and reopen it, and it should fix the issue.

Categories

Resources