from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
I'm following tensorflow but when I try to import tensorflow_hub, error occurs like
Traceback (most recent call last):
File "C:/PythonProjects/191217_TensorFlow_Project/model3.py", line 7, in <module>
import tensorflow_hub as hub
File "C:\Users\UserK\Anaconda3\envs\191217_TensorFlow_Project_1\lib\site-packages\tensorflow_hub\__init__.py", line 53, in <module>
from tensorflow_hub.keras_layer import KerasLayer
File "C:\Users\UserK\Anaconda3\envs\191217_TensorFlow_Project_1\lib\site-packages\tensorflow_hub\keras_layer.py", line 39, in <module>
class KerasLayer(tf.keras.layers.Layer):
AttributeError: 'function' object has no attribute 'layers'
I don't have any file named 'tensorflow_hub.py', so i don't know why it happens.
Related
In windows 11 spyder(python 3.8)
The command:
import tensorflow_datasets as tfds
yeilds:
Traceback (most recent call last):
File "C:\Users\gkhaz\AppData\Local\Temp/ipykernel_16868/45766485.py", line 1, in
import tensorflow_datasets as tfds
File "C:\Users\gkhaz\anaconda3\lib\site-packages\tensorflow_datasets_init_.py", line 64, in
from tensorflow_datasets import vision_language
File "C:\Users\gkhaz\anaconda3\lib\site-packages\tensorflow_datasets\vision_language_init_.py", line 20, in
from tensorflow_datasets.vision_language.wit import Wit
File "C:\Users\gkhaz\anaconda3\lib\site-packages\tensorflow_datasets\vision_language\wit_init_.py", line 18, in
from tensorflow_datasets.vision_language.wit.wit import Wit
File "C:\Users\gkhaz\anaconda3\lib\site-packages\tensorflow_datasets\vision_language\wit\wit.py", line 25, in
csv.field_size_limit(sys.maxsize)
OverflowError: Python int too large to convert to C long
I tried importing Lasagne in my code which is as follows:
from __future__ import print_function
import sys
import os
import time
import string
import random
import pickle
import numpy as np
import theano
import theano.tensor as T
import lasagne
But on running the file I keep getting the following error:
File "main_cifar_100_theano.py", line 12, in <module>
import lasagne
File "/usr/local/lib/python3.7/dist-packages/lasagne/__init__.py", line 19, in <module>
from . import layers
File "/usr/local/lib/python3.7/dist-packages/lasagne/layers/__init__.py", line 5, in <module>
from .noise import *
File "/usr/local/lib/python3.7/dist-packages/lasagne/layers/noise.py", line 6, in <module>
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
ImportError: cannot import name 'MRG_RandomStreams' from 'theano.sandbox.rng_mrg' (/usr/local/lib/python3.7/dist-packages/theano/sandbox/rng_mrg.py)
Please help me resolve this issue.
I am getting that error while importing tensorflow_probability in IDLE(Default python editor). I don't get that error if use same code in VS code. Works perfectly fine in VS code.
Here are my imports
import numpy as np
import tensorflow.compat.v1 as tf
import tensorflow_probability as tfp
tf.disable_v2_behavior()
Here is complete error
Traceback (most recent call last):
File "C:\Python Scripts\pos_tagging.py", line 4, in <module>
import tensorflow_probability as tfp
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\__init__.py", line 77, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\__init__.py", line 21, in <module>
from tensorflow_probability.python import bijectors
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\__init__.py", line 23, in <module>
from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\absolute_value.py", line 23, in <module>
from tensorflow_probability.python.bijectors import bijector
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\bijector.py", line 31, in <module>
from tensorflow_probability.python.internal import distribution_util
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\distribution_util.py", line 28, in <module>
from tensorflow_probability.python.internal import prefer_static
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\prefer_static.py", line 30, in <module>
from tensorflow_probability.python.internal.backend import numpy as nptf
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\__init__.py", line 21, in <module>
from tensorflow_probability.python.internal.backend.numpy import bitwise
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\bitwise.py", line 23, in <module>
from tensorflow_probability.python.internal.backend.numpy import _utils as utils
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\_utils.py", line 26, in <module>
from tensorflow_probability.python.internal.backend.numpy import nest
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\nest.py", line 34, in <module>
from tree import _assert_shallow_structure
ImportError: cannot import name '_assert_shallow_structure' from 'tree' (C:\Users\aaaa\AppData\Local\Programs\Python\Python38\Lib\idlelib\tree.py)
Python Version:3.8.5 64 bit
Windows machine
Look at where it's importing from (C:\Users\aaaa\AppData\Local\Programs\Python\Python38\Lib\idlelib\tree.py) I think you meant to import from dm-tree.
Here's my solution:
if you don't have dm-tree installed
pip install dm-tree
if you do, install PyCharm and use that to run the code. It wont have the conflict that IDLE would on the tree.py
I have made my own class in python, but while making an object it gives strange error "AttributeError: module 'IPython' has no attribute 'utils'". This error is coming from the import statement in the init function in my module. I am importing from moviepy.
I have tried writing the import statement outside the class. I am trying to make an importable package for my personal use.
class video_reader_writer:
def __init__(self,video_file):
from moviepy.editor import ImageSequenceClip // error here
from moviepy.audio.AudioClip import AudioArrayClip
import numpy as np
...
This is the stack trace :
from moviepy.editor import ImageSequenceClip
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\editor.py", line 49, in <module>
from .video.io.html_tools import ipython_display
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\html_tools.py", line 20, in <module>
from IPython.display import HTML
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\__init__.py", line 54, in <module>
from .core.application import Application
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\ultratb.py", line 128, in <module>
import IPython.utils.colorable as colorable
AttributeError: module 'IPython' has no attribute 'utils'
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 4 years ago.
I'm working with a project and somewhere down the line my I have to uninstall and reinstall numpy to fix a problem, but then this happened
Traceback (most recent call last):
File "ori2.py", line 3, in <module>
import numpy as np
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/core/__init__.py", line 38, in <module>
from . import numeric
File "/home/tsoi/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy/core/numeric.py", line 43, in <module>
import pickle
File "/home/tsoi/Documents/environments/testvenv/Traffic-rec/pickle.py", line 1
from ~/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy import numpy as np
^
SyntaxError: invalid syntax
I have also tried
import sys
sys.path.append('~/Documents/environments/testvenv/my_venv/lib/python3.6/site-packages/numpy')
when importing numpy but the same error occured, This hasn't happened before and it's been annoying for me. This is the part of my code that I think is relevant to this problem:
from __future__ import print_function
#from comet_ml import Experiment
import numpy as np
import tensorflow as tf
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.datasets import fashion_mnist
from keras.models import Model
from keras.layers import Input, Dense
from keras.models import load_model
import cv2
import os
import glob
from os import path
import random
UPDATE:
Yeah you right user2357112
numpy is importing your file '/home/tsoi/Documents/environments/testvenv/Traffic-rec/pickle.py' instead of the pickle module, delete the file or rename it, then the problem should be fixed.