I have been trying to get a tutorial working, that uses the keras_squeezenet package in Python. When I try to run one of the files, I get an ImportError. I have tried both adding a line to import keras, and to import keras_squeezenet at the top, but this hasn't fixed the problem. The full error message:
File "train_model.py", line 4, in <module>
from keras_squeezenet import SqueezeNet
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\keras_squeezenet\__init__.py", line 2, in <module>
from keras_squeezenet.squeezenet import SqueezeNet
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\keras_squeezenet\squeezenet.py", line 1, in <module>
from keras_applications.imagenet_utils import _obtain_input_shape
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\keras_applications\imagenet_utils.py", line 14, in <module>
backend = get_keras_submodule('backend')
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\keras_applications\__init__.py", line 34, in get_keras_submodule
raise ImportError('You need to first `import keras` '
ImportError: You need to first `import keras` in order to use `keras_applications`. For instance, you can do:
import keras
from keras_applications import vgg16
Or, preferably, this equivalent formulation:
from keras import applications
If anyone could please help me with this error, it would be greatly appreciated.
You need first to write the following before the line from keras_squeezenet:
import keras
from keras_applications import vgg16
Related
I'm trying to run a python program that uses the pandas library on Mac OS, and I get the next error
adan_vazquez#EPAM-C02G513RML7L automate_python % python3 test_pandas.py
Traceback (most recent call last):
File "/Users/adan_vazquez/Desktop/automate_python/test_pandas.py", line 1, in <module>
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 155, in <module>
from . import random
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/__init__.py", line 180, in <module>
from . import _pickle
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 1, in init numpy.random.mtrand
File "bit_generator.pyx", line 40, in init numpy.random.bit_generator
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/secrets.py", line 19, in <module>
from random import SystemRandom
File "/Users/adan_vazquez/Desktop/automate_python/random.py", line 3, in <module>
print(random.randint(1,10))
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)
Here's the code that I'm trying to run:
import pandas as pd
simpsons = pd.read_html('https://en.wikipedia.org/wiki/List_of_The_Simpsons_episodes_(seasons_1%E2%80%9320)')
print(len(simpsons))
print("Hola")
As you can see is not a big code and I'm getting the error, I already updated my pip3 and my python3 versions, also I reinstall pandas and I keep getting the error, if I try to import pandas in the python terminal I get the same error and I don't know what's causing it, I hope you can help me, thanks in advance.
The error message says it is a circular import error.
Try renaming /Users/adan_vazquez/Desktop/automate_python/random.py with something other than random
According to the error, it is a circular import which is causing the problem.
Since I do not have the details of your project structure or file name, my best guess is that you accidentally named your working file the same as the module name and those modules depend on each other.
I've followed the instructions in Detectron and I've configured it several times: the code compiles as it should. When it comes to run the code, I get this error:
Traceback (most recent call last):
File "tools/train_net_step.py", line 21, in <module>
import nn as mynn
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/nn/__init__.py", line 2, in <module>
from .parallel import DataParallel
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/nn/parallel/__init__.py", line 3, in <module>
from .data_parallel import DataParallel, data_parallel
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/nn/parallel/data_parallel.py", line 4, in <module>
from .scatter_gather import scatter_kwargs, gather
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/nn/parallel/scatter_gather.py", line 8, in <module>
from torch.utils.data.dataloader import numpy_type_map
ImportError: cannot import name 'numpy_type_map'
I've also tried to google it many times, but I can't find a way to solve it. What can I do? I'm using PyTorch 0.4.1 and pytorch nightly 1.0.0-dev.
EDIT: Thanks to sancelot, I managed to solve that error (PyTorch 0.4.0 did the thing). Anyway, now I've got another error:
Traceback (most recent call last):
File "tools/train_net_step.py", line 27, in <module>
from modeling.model_builder import Generalized_RCNN
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/modeling/model_builder.py", line 11, in <module>
from model.roi_pooling.functions.roi_pool import RoIPoolFunction
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/model/roi_pooling/functions/roi_pool.py", line 3, in <module>
from .._ext import roi_pooling
File "/home/federico/PycharmProjects/Detectron.pytorch/lib/model/roi_pooling/_ext/roi_pooling/__init__.py", line 3, in <module>
from ._roi_pooling import lib as _lib, ffi as _ffi
ImportError: /home/federico/PycharmProjects/Detectron.pytorch/lib/model/roi_pooling/_ext/roi_pooling/_roi_pooling.so: undefined symbol: PyInt_FromLong
What I can't get this time is: is this an error given by an external library? I'm using an anaconda environment previously made by my professor, who has used it for Detectron... so I can't guess why I get this.
Yeah, these are due to Pytorch version mismatch. Solution depends on what extent you are willing to go, sometimes if you are okay with hacking and just getting it running, then just copy paste the numpy_type_map from older versions:
numpy_type_map = {
'float64': torch.DoubleTensor,
'float32': torch.FloatTensor,
'float16': torch.HalfTensor,
'int64': torch.LongTensor,
'int32': torch.IntTensor,
'int16': torch.ShortTensor,
'int8': torch.CharTensor,
'uint8': torch.ByteTensor,
}
Or, up to version 1.1.0, you can try replacing the import statement,
from:
from torch.utils.data.dataloader import numpy_type_map
to:
from torch.utils.data._utils.collate import numpy_type_map
N.b. will still break in more recent versions. Again, this is a hacky quick-fix solution.
I suppose there is a version mismatch between detectron and the needed pytorch release you are using.
if you look at latest pytorch source code, there is no numpy_type_map component.
https://github.com/pytorch/pytorch/blob/master/torch/utils/data/dataloader.py
Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.
This is my code:
import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
pd.read_csv(rawData)
Here is the Error:
C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
File "FILEPATH/Main.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
from __future__ import division, absolute_import, print_function
File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'
Any suggestions for why this isn't working would be greatly appreciated.
You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:
import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
pd.read_csv(rawData)
I'm trying to submit a PR for scikit-image, but I get a Travis-CI error:
Traceback (most recent call last):
File "doc/examples/edges/plot_canny.py", line 22, in <module>
from skimage import feature
File "/home/travis/build/scikit-image/scikit-image/skimage/feature/__init__.py", line 9, in <module>
from .peak import peak_local_max
File "/home/travis/build/scikit-image/scikit-image/skimage/feature/peak.py", line 3, in <module>
from ..filters import rank_order
File "/home/travis/build/scikit-image/scikit-image/skimage/filters/__init__.py", line 11, in <module>
from ._frangi import frangi_filter, hessian_filter
File "/home/travis/build/scikit-image/scikit-image/skimage/filters/_frangi.py", line 2, in <module>
from skimage.feature import hessian_matrix, hessian_matrix_eigvals
ImportError: cannot import name hessian_matrix
I suppose that this might be a circular import error, but I don't quite get how to resolve the issue. I've already included frangi_filter and hessian_filter into filter's module __init__.py.
I've also tried relative import, which resulted into the same errors.
How can I do a proper import, so the circular import issue can be resolved?
One ugly hack to resolve this would be to move that import inside the function, like
def hessian_filter(image, scale=(1, 10), scale_ratio=2, beta1=0.5, beta2=15):
"""
Blah-blah-blah
"""
from ..feature import hessian_matrix, hessian_matrix_eigvals
# function body
You might want to create separate "proxy" functions for hessian_matrix and hessian_matrix_eigvals to not pollute every function with imports.
So I am having a bit of trouble using scipy. I have been importing data from a .mat file (matlab variables) and up until today it has worked perfectly. I have no idea what changed or when because I have been developing a text - based data format so that I can avoid depending on Matlab for writing my data. Anyways, I am getting a bizzare import error when I import scipy.io
import scipy.io
myData = scipy.io.loadmat('some_data_file')
When I run this I get the following error:
>>> import scipy.io
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\pyzo2014a\lib\site-packages\scipy\io\__init__.py", line 85, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\mio.py", line 13, in <module>
from .mio4 import MatFile4Reader, MatFile4Writer
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\mio4.py", line 11, in <module>
import scipy.sparse
File "C:\pyzo2014a\lib\site-packages\scipy\sparse\__init__.py", line 217, in <module>
from .csgraph import cs_graph_components
File "C:\pyzo2014a\lib\site-packages\scipy\sparse\csgraph\__init__.py", line 148, in <module>
from ._shortest_path import shortest_path, floyd_warshall, dijkstra,\
ImportError: No module named 'scipy.sparse.csgraph._shortest_path'
I thought there might be something wrong with my python distribution so I reinstalled it, however the problem persists, and now the installer says it can't find '_shortest_path.py' when it is installing. When I navigate to .../Libs/site-packages/scipy/sparse/csgraph/ I find that indeed there is no module named _shortest_path. I don't understand how this error came about or how anything in my code would change it. Has anyone else come across this problem?
I am using Pyzo 2014 on Windows 7 x64.
Restore shortest_path.pyd in your virust chest
http://www.blendernation.com/2014/06/28/getting-a-virus-warning-with-blender-2-71-heres-why/