Cannot import name 'MRG_RandomStreams' from 'theano.sandbox.rng_mrg' - python

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.

Related

Why the attribute error occurs when importing tensorflow_hub?

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.

SyntaxError: invalid syntax when importing numpy [duplicate]

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.

"Import Error: cannot import name 'unicode_literals' "

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)

Error when trying to execute a python script using py2exe

I tried many ways to make my code executable and I tried (pypinstaller,py2exe,cx_Freeze) without any results, therefore I focused on py2exe and I solved almost all errors which I faced while using this way, but the last error as I attached below is very difficult to solve it and I wasted a lot of time to solve it and I didn't catch any result, when I tried to run the executable file I got a CMD window with the below error and it disappear quickly, kindly help me to solve it or inform me by a way is supporting (xlrd,openpyxl,selenium,xlsxwriter,pytesser) libraries to I use it to execute my code instead of py2exe,
Traceback (most recent call last):
File "semiFULLTWO.py", line 8, in <module>
File "openpyxl\ init .pyc", line 29, in <module>
File "openpyxl\workbook\ init .pyc", line 5, in <module>
File "openpyxl\workbook\workbook.pyc", line 17, in <module>
File "openpyxl\writer\write_only.pyc", line 23, in <module>
File "openpyxl\writer\excel.pyc", line 36, in <module>
File "openpyxl\packaging\extended.pyc", line 4, in <module>
ImportError: cannot import name _version_
the libraries which I'm using :
*# -*- coding: utf-8 -*-
import os
import time
import xlrd
import base64
import urllib
import requests
import openpyxl
import xlsxwriter
from PIL import Image
from lxml import etree
from io import BytesIO
from pytesser import *
from openpyxl import Workbook
from datetime import datetime
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select*
the error related to openpyxl lib :
only_date = str ( dt.date ( ) )
workbook = xlsxwriter.Workbook ( only_date + '.xlsx' )
worksheet = workbook.add_worksheet ( )

invalid elf header error for .so file

I'm trying to run a script in python, and I'm getting an "invalid elf header" error. I have a series of scripts that call one another, I'll go ahead and include those as well:
import sys
sys.path.append("/home/smh/Linux/Desktop/gras-03-03/python")
from python_utilities import GRASTestor
which calls GRASTestor.py
from BaseTestor import BaseTestor
import numpy as np
import hepunit as unit
from gdml_writer import gdml_writer
from GDMLGeometryBuilder import GDMLGeometryBuilder
from GRASMacroBuilder import GRASMacroBuilder,GRASRMCMacroBuilder
from Plotters import Plotter
import os
import sys
import SpenvisCSVFileHandler
which calls SpenvisCSVFileHandler.py
import string
import Spenvis.so
import os
from numpy import *
which is where we get our error, specifically with the line "import Spenvis.so"
/home/smh/Linux/Desktop/gras-03-03/python/python_utilities
Traceback (most recent call last):
File "perform_gras_rmc_tests.py", line 6, in <module>
from python_utilities import GRASTestor
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/GRASTestor.py", line 19, in <module>
import SpenvisCSVFileHandler
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/SpenvisCSVFileHandler.py", line 8, in <module>
import Spenvis.so
ImportError: /home/smh/Linux/Desktop/gras-03-03/python/python_utilities/Spenvis.so: invalid ELF header
And I'm not certain why it's not working. Any suggestions would be appreciated!
Never mind. Upon looking at the file architecture, it appears the file Spenvis.so is mac specific for some reason. Just need to get the correct file, then.

Categories