module 'pyomo' has no attribute 'AbstractModel' - python

I have installed pyomo and trying to create a instance model from AbstractModel as follows:
import pyomo as pmo
absmd = pmo.AbstractModel()
Traceback (most recent call last):
File "", line 1, in
absmd = pmo.AbstractModel()
But i am getting the following error:
AttributeError: module 'pyomo' has no attribute 'AbstractModel'
Any advise?

You're importing the wrong stuff. Either use pmo.environ.AbstractModel() or
from pyomo.environ import *
model = AbstractModel()

Related

Can not find a specific regular expressions

I am trying to scrap specific information from the site but I am receiving an error. Here is the simplified version of the main problem:
import re
b='href="/bp/vendor?vendorCodes=C901U">C901U</a></span></div></div></div><div heyaa'
c=re.search('href="/bp/vendor?vendorCodes=C901U">C901U</a></span></div></div></div><div',b)
If I try to find what is in c I receive this error:
c.group()
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
c.group()
AttributeError: 'NoneType' object has no attribute 'group'
Thanks in advance.

AttributeError: module 'lyrics' has no attribute 'Domain'

I am having troubles with making my code running in Python3 (it was in Python2 and I am converting it).
Here is the project structure:
lyrics/__init__.py
lyrics/lyrics.py
./manifold.py
in manifold.py :
import lyrics as lyr
lyr.Domain(label="Points", data=X)
where Domain class is defined in lyrics/lyrics.py:
class Domain(object):
...
When I execute manifold.py with:
./manifold.py
I get this error:
Traceback (most recent call last): File "./manifold.py", line 76, in
Points = lyr.Domain(label="Points", data=X) AttributeError: module 'lyrics' has no attribute 'Domain'
Any idea ?
Thank you
[EDIT]
in lyrics/init.py
from lyrics import *
from . import functions

'tensorflow' has no attribute 'config' error

I am trying to run the following lines:
import tensorflow as tf
physical_devices = tf.config.list_physical_devices("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
I am trying to run this lines too:
import tensorflow as tf
physical_devices = tf.test.gpu_device_name("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
But the first method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 4, in <module>
physical_devices = tf.config.list_physical_devices("GPU")
AttributeError: module 'tensorflow' has no attribute 'config'
And the second method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 5, in <module>
for i in range(len(tf.test.gpu_device_name("GPU"))):
AttributeError: module 'tensorflow' has no attribute 'test'
I am using Tensorflow 2.4.0 .Any ideas what I'm doing wrong?
If anyone could help that would be great:)
Thank's for every help in advance:)
I read that you already fixed it but since you didn't included it in your post here is the solution everyone else having this error: you need to change some modules from e.g. tf.config.list_physical_devices("GPU") to tf.compat.v1.config.list_physical_devices("GPU"). By adding ".compat.v1" you are ensuring backwards capability. You can use this code snippet for all other modules, that don't work.

AttributeError: module 'keras.preprocessing' has no attribute 'text'

When I am trying to import the Tokenizer() function in Keras, I am getting the following error.
I am following official Keras documentation at https://keras.io/preprocessing/text/#tokenizer
import keras
tokenizer = keras.preprocessing.text.Tokenizer()
Getting error like this :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'keras.preprocessing' has no attribute 'text'
Using Keras version '2.1.3'
Where I have done wrong?
You want
from keras.preprocessing import text
tokenizer = text.Tokenizer(...)
The reason is that keras/preprocessing/__init__.py doesn't import nor expose the text submodule

Why scipy.io.wavfile.read does not return a tuple?

I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...

Categories