I have been trying to import theano.tensor in my code.
I have used theano.tensor before. All of my previous code importing theano.tensor works perfectly in my machine. Now I am trying to write another script importing the tensor from theano and I am getting the following exception.
Traceback (most recent call last):
File "code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/__init__.py", line 52, in <module>
from theano.gof import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/__init__.py", line 56, in <module>
from theano.gof.opt import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 11, in <module>
import pdb
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
File "/localtmp/saikat/CovInfo/Closure/code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/__init__.py", line 6, in <module>
from theano.tensor.basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/basic.py", line 17, in <module>
from theano.tensor import elemwise
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/elemwise.py", line 13, in <module>
from theano import scalar
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/__init__.py", line 2, in <module>
from .basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/basic.py", line 25, in <module>
from theano import gof, printing
File "/anaconda3/lib/python3.5/site-packages/theano/printing.py", line 22, in <module>
from theano.compile import Function, debugmode, SharedVariable
File "/anaconda3/lib/python3.5/site-packages/theano/compile/__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py", line 22, in <module>
import theano.compile.mode
File "/anaconda3/lib/python3.5/site-packages/theano/compile/mode.py", line 77, in <module>
OPT_NONE = gof.Query(include=[], exclude=exclude)
AttributeError: module 'theano.gof' has no attribute 'Query'
I cannot find any plausible reason for this exception.
I guess i got your problem. See in the error log:
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
I believe there is another script called code.py in Theano which gets called from pdb.py when python interpreter executes your script which is also named as code.py. I am guessing python interpreter is mixing up these two scripts and executing the wrong one! You can change the filename and check whether the error disappear or not.
Related
I am trying to create my own PyEnvironment for TF-Agents.
However, this error keeps showing up:
AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'
I have found out that this seems to be an issue with tensorflow-probability, but I have installed the version tensorflow-probability=0.7.0 recommended at
https://github.com/tensorflow/agents/issues/91
I have tried reinstalling and updating
tensorflow-gpu=2.0.0-beta1
tf-agents-nightly
tensorflow-probability=0.7.0
Here is a minimal code example:
from tf_agents.environments import py_environment
class myEnv(py_environment.PyEnvironment):
def __init__(self):
pass
def _reset(self):
pass
def _step(self, action):
pass
This is the full error message when running this minimum example:
Traceback (most recent call last): File ".\env_mwe.py", line 1, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\__init__.py", line 18, in <module>
from tf_agents.environments import batched_py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\batched_py_environment.py", line 33, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\py_environment.py", line 29, in <module>
from tf_agents.trajectories import time_step as ts File "C:\Python37\lib\site-packages\tf_agents\trajectories\__init__.py", line 19, in <module>
from tf_agents.trajectories import time_step File "C:\Python37\lib\site-packages\tf_agents\trajectories\time_step.py", line 28, in <module>
from tf_agents.specs import array_spec File "C:\Python37\lib\site-packages\tf_agents\specs\__init__.py", line 20, in <module>
from tf_agents.specs.distribution_spec import DistributionSpec File "C:\Python37\lib\site-packages\tf_agents\specs\distribution_spec.py", line 22, in <module>
import tensorflow_probability as tfp File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\__init__.py", line 78, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\__init__.py", line 22, in <module>
from tensorflow_probability.python import distributions File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\__init__.py", line 64, in <module>
from tensorflow_probability.python.distributions.linear_gaussian_ssm import LinearGaussianStateSpaceModel File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\linear_gaussian_ssm.py", line 41, in <module>
_matmul = linear_operator_util.matmul_with_broadcast AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'
Found it!
In order to use tensorflow-gpu with tensorflow-probability, one needs to install tfp-nightly
So pip3 install --upgrade tfp-nightly did the trick
To use 2.0.0beta1 requires tfp-nightly.
I am using python 3.5 and installed tensorflow-gpu 1.12.0 on Linux. When I run this in python3.5:
import tensorflow as tf
It works fine with no errors.
However, when I run:
import tensorflow.contrib
There is an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/__init__.py", line 49, in <module>
from tensorflow.contrib import distributions
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/distributions/__init__.py", line 38, in <module>
from tensorflow.contrib.distributions.python.ops.estimator import *
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/distributions/python/ops/estimator.py", line 21, in <module>
from tensorflow.contrib.learn.python.learn.estimators.head import _compute_weighted_loss
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/__init__.py", line 96, in <module>
from tensorflow.contrib.learn.python.learn import *
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/__init__.py", line 28, in <module>
from tensorflow.contrib.learn.python.learn import *
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/__init__.py", line 30, in <module>
from tensorflow.contrib.learn.python.learn import estimators
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/estimators/__init__.py", line 302, in <module>
from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNClassifier
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py", line 35, in <module>
from tensorflow.contrib.learn.python.learn.estimators import dnn_linear_combined
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py", line 36, in <module>
from tensorflow.contrib.learn.python.learn.estimators import estimator
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 52, in <module>
from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/learn_io/__init__.py", line 26, in <module>
from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
File "/home/myname/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/learn_io/dask_io.py", line 33, in <module>
import dask.dataframe as dd
File "/home/myname/anaconda3/lib/python3.5/site-packages/dask/dataframe/__init__.py", line 1, in <module>
from .core import (DataFrame, Series, Index, _Frame, map_partitions,
File "/home/myname/anaconda3/lib/python3.5/site-packages/dask/dataframe/core.py", line 23, in <module>
from .. import array as da
File "/home/myname/anaconda3/lib/python3.5/site-packages/dask/array/__init__.py", line 4, in <module>
from .core import (Array, stack, concatenate, take, tensordot, transpose,
File "/home/myname/anaconda3/lib/python3.5/site-packages/dask/array/core.py", line 13, in <module>
from toolz.curried import (pipe, partition, concat, unique, pluck, join, first,
File "/home/myname/anaconda3/lib/python3.5/site-packages/toolz/curried/__init__.py", line 53, in <module>
_curry_namespace(vars(toolz)),
File "/home/myname/anaconda3/lib/python3.5/site-packages/toolz/curried/__init__.py", line 48, in _curry_namespace
for name, f in ns.items() if '__' not in name
File "/home/myname/anaconda3/lib/python3.5/site-packages/toolz/curried/__init__.py", line 48, in <genexpr>
for name, f in ns.items() if '__' not in name
File "/home/myname/anaconda3/lib/python3.5/site-packages/toolz/curried/__init__.py", line 42, in _should_curry
return (callable(f) and _nargs(f) > 1 or f in do_curry)
File "/home/myname/anaconda3/lib/python3.5/site-packages/toolz/curried/__init__.py", line 35, in _nargs
return len(inspect.getargspec(f).args)
File "/home/myname/anaconda3/lib/python3.5/inspect.py", line 1050, in getargspec
raise ValueError("Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
I searched for getfullargspec() API but got even more confused. As far as I know, the getfullargspec() API from inspect can only do with something like
getfullargsspec(function_name)
How can I do with it? I could appreciate it a lot if you could explain the cause and also possibly a simple solution.
Plus, I am running the code on a remote server without root permission. Command lines such as
sudo xxxxx
do not work for me.
Thank you for your help!
I also face this problem. I found this way to solve this problem.
conda install toolz
Good Luck
im trying to import matplotlib.pyplot, here is my code:
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
I'm using the Geany IDE under Ubuntu 16.04.03, and i'm getting the
following errormessage
[1, 2, 3, 4, 5]
Traceback (most recent call last):
File "mpl_squares.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python3.5/dist-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/usr/local/lib/python3.5/dist-packages/matplotlib/cbook.py", line 32, in <module>
import numpy as np
File "/usr/local/lib/python3.5/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/local/lib/python3.5/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "/usr/local/lib/python3.5/dist-packages/numpy/core/_internal.py", line 18, in <module>
from .numerictypes import object_
File "/usr/local/lib/python3.5/dist-packages/numpy/core/numerictypes.py", line 962, in <module>
_register_types()
File "/usr/local/lib/python3.5/dist-packages/numpy/core/numerictypes.py", line 958, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
This error occurs only when i'm using the Geany IDE, when i'm running the
code in the terminal it works fine.
Has somebody an idea what's wrong with Geany?
Thanks in advance!
With Geany your working directory is different. I'm thinking it's the same as here:
https://www.reddit.com/r/learnpython/comments/5pvdjk/module_object_has_no_attribute_integral/
I used py2exe to build an exe of a program that uses scipy and numpy and I get the next error in the log file when I tried to run the program.
Traceback (most recent call last):
File "GLP2-e Admin.pyw", line 24, in <module>
File "C:\Python34\lib\site-packages\scipy\ndimage\__init__.py", line 161, in <module>
from .filters import *
File "C:\Python34\lib\site-packages\scipy\ndimage\filters.py", line 37, in <module>
from scipy.misc import doccer
File "C:\Python34\lib\site-packages\scipy\misc\__init__.py", line 51, in <module>
from scipy.special import comb, factorial, factorial2, factorialk
File "C:\Python34\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\Python34\lib\site-packages\scipy\special\basic.py", line 18, in <module>
from . import orthogonal
File "C:\Python34\lib\site-packages\scipy\special\orthogonal.py", line 101, in <module>
from scipy import linalg
File "C:\Python34\lib\site-packages\scipy\linalg\__init__.py", line 190, in <module>
from ._decomp_update import *
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (No module named 'scipy.linalg.cython_blas') 'Y:\\Factory\\GLP2-e Admin (Todos los archivos)\\Compilaciones\\VersiĆ³n 2.1\\dist\\scipy.linalg._decomp_update.pyd'
I have tried some thing like put my setup.py file like this:
options ={
'py2exe': {
'bundle_files' : 3,
r'includes':[r'scipy.sparse.csgraph._validation',
r'scipy.special._ufuncs_cxx',],
'packages' : ['encodings'],
}
},
But it doesn't work and I still get that error.
I don't know what to do to solve this issue...
Hope you can help me.
Thanks.
I have been solve the issue adding in the "includes" section of my setup.py all the files that the log file return me as missing. After 7 files, the program run without any error.
I've encountered a very strange error when trying to Import mayavi. A few minutes ago it worked like a charm, but now there's something going wrong and I've no clue why.
I start python from the terminal and then I type:
from mayavi import mlab
The error I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/mayavi/mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "/usr/lib/python2.7/dist-packages/mayavi/tools/camera.py", line 23, in <module>
from engine_manager import get_engine
File "/usr/lib/python2.7/dist-packages/mayavi/tools/engine_manager.py", line 14, in <module>
from mayavi.core.engine import Engine
File "/usr/lib/python2.7/dist-packages/mayavi/core/engine.py", line 28, in <module>
from mayavi.core.scene import Scene
File "/usr/lib/python2.7/dist-packages/mayavi/core/scene.py", line 15, in <module>
from mayavi.core.source import Source
File "/usr/lib/python2.7/dist-packages/mayavi/core/source.py", line 19, in <module>
from mayavi.core.module_manager import ModuleManager
File "/usr/lib/python2.7/dist-packages/mayavi/core/module_manager.py", line 19, in <module>
from mayavi.core.lut_manager import LUTManager
File "/usr/lib/python2.7/dist-packages/mayavi/core/lut_manager.py", line 10, in <module>
import subprocess
File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
import pickle
File "pickle.py", line 4, in <module>
from mayavi import mlab
ImportError: cannot import name mlab
What's wrong with Python?
You have a local file named pickle.py; this is being imported instead of the pickle module. This module then tries to import mlab before that module itself has completed importing in a circular import dependency:
File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
import pickle
File "pickle.py", line 4, in <module>
from mayavi import mlab
Note how subprocess tries to import pickle and finds your file instead (the path is relative instead of a full path inside /usr/lib/python2.7/.
Rename pickle.py to something else, you are masking the standard library here.