No module named ‘torchvision.models.utils‘ - python

When I use the environment of pytorch=1.10.0, torchvision=0.11.1 to run the code, I run to the statement from torchvision.models.utils import load_state_dict_from_url. The following error will appear when:
>>> from torchvision.models.utils import load_state_dict_from_url
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torchvision.models.utils'

After consulting torchvision's code repository, there is a solution:
Note that this syntax is only for higher versions of PyTorch.
The original code from .utils import load_state_dict_from_url is not applicable.
you connot import load_state_dict_from_url from .utils.
change .utils to torch.hub can fix the problem.
from torch.hub import load_state_dict_from_url
This worked for me.

Related

ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'

I found several questions about the same issue here and here
from pyfinance.ols import PandasRollingOLS
I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 78, in <module>
from pandas.tseries.frequencies import FreqGroup, get_freq_code
ImportError: cannot import name 'FreqGroup' from 'pandas.tseries.frequencies' (/usr/local/lib/python3.8/site-packages/pandas/tseries/frequencies.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/pyfinance/__init__.py", line 32, in <module>
from .returns import TFrame, TSeries # noqa
File "/usr/local/lib/python3.8/site-packages/pyfinance/returns.py", line 42, in <module>
from pyfinance import ols, utils
File "/usr/local/lib/python3.8/site-packages/pyfinance/ols.py", line 15, in <module>
from pyfinance import utils
File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 80, in <module>
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'
I tried uninstalling and reinstalling pandas versions 1.1.3, 1.1.2, 1.1.1 and none of them work, I just get the same error, I then tried building pandas in the following fashion:
!python setup.py build_ext --inplace --force
And I still get the same error
Just for reference
I did some digging and it looks like pandas changed their api, which results in the error mentioned. I modified the source code and included the right imports which are in pyfinance/utils.py:
In line 77 changed from:
try:
from pandas.tseries.frequencies import FreqGroup, get_freq_code
except ImportError: # 0.24+, or somewhere around then
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
to
try:
from pandas.tseries.frequencies import FreqGroup, get_freq_code
except ImportError:
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas.tests.tslibs.test_period_asfreq import get_freq_code
I created a pull request here if you're facing the same problem, you may clone and install my fork
Make sure you have the right version of pyfinance. Installing 0.1.3 solved my issue.
https://pypi.org/project/pyfinance/0.1.3/

slicer3d and python pyradiomics error

I'm trying to use pyradiomics extension on slicer 3d. I have an issue that I think it's related to my python installation. I tried to reinstall pyradiomics with no results. This is the error I get
RadiomicsCLI standard error:
Traceback (most recent call last):
File "/Applications/Slicer.app/Contents/Extensions-26813/SlicerRadiomics/lib/Slicer-4.8/cli-modules/SlicerRadiomicsCLIScript", line 6, in <module>
from radiomics.scripts import commandline
File "/Applications/Slicer.app/Contents/Extensions-26813/SlicerRadiomics/lib/python2.7/site-packages/radiomics/__init__.py", line 4, in <module>
import collections # noqa: F401
File "/Applications/Slicer.app/Contents/lib/Python/lib/python2.7/collections.py", line 20, in <module>
from _collections import deque, defaultdict
ImportError: No module named _collections
RadiomicsCLI completed with errors
anybody has an idea on how to solve this?
This was a build error and has since been fixed.

How to import a Python module into Jython?

I can use the module correctly by Python, but when using Jython, some error occurs...
Code:
from jieba import *
Errors:
Traceback (most recent call last):
File "/Users/Jack/Documents/workspace/FirstJython/hellojyphon.py", line 8, in <module>
from jieba import *
File "/Users/Jack/Documents/workspace/FirstJython/jieba/__init__.py", line 15, in <module>
from ._compat import *
ImportError: No module named _compat
Is there any differences between Python and Jython when import?
I solve it by myself.
There is something wrong when using relative directories in Jython.
so after I change ._compat to jieba._compat, the problem solved!
But I don't exactly know the reason...

ImportError no module named calendar

I have installed Python 2.7.5 on my Windows 7 host. I want to use the CalendarCtrl widget which is part of 'wx.calendar' module. When I try to import calendar I get the following error:
>>> import wx
>>> import wx.calendar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named calendar
On Linux host I have no problem with the
import wx.calendar
statement. Any help to resolve the issue is much appreciated.

unable to import ctypes module in nuke6.1v2

as from title, if I try to import ctypes in nuke6.1v2 I get this error:
import ctypes
# Result: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Nuke6.1v2\lib\ctypes\__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
I also tryed to import it from the Python 2.6 main folder but with no luck.
However, if I try to import it in another package (softimage for example) I have no problem at all.
I have found a lot of people having the same problem, but none of the solutions worked for me.
Any idea?
Thanks

Categories

Resources