I am trying to run this simple code
import numpy as np
bmi = np.array([12,123,34])
print bmi
When I execute it however I get the following error:
Traceback (most recent call last):
File "sample10.py", line 1, in <module>
import numpy as np
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\core\__init__.py", line 21, in <module>
from . import function_base
File "C:\Users\Marc\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\core\function_base.py", line 6, in <module>
from .numeric import result_type, NaN, shares_memory, MAY_SHARE_BOUNDS, TooHardError
ImportError: cannot import name shares_memory
Any thoughts what might be causing this? When Im running
python --version
I get 2.7.11
Related
I use python3.6.0 (googletrans3.0). I import googletrans3.0.
Traceback (most recent call last):
File "C:\Python\Python36-32\traduction essai.py", line 3, in <module>
import googletrans
File "C:\Python\Python36-32\lib\site-packages\googletrans\__init__.py", line 6, in <module>
from googletrans.client import Translator
File "C:\Python\Python36-32\lib\site-packages\googletrans\client.py", line 10, in <module>
import httpcore
File "C:\Python\Python36-32\lib\site-packages\httpcore\__init__.py", line 2, in <module>
from ._async.connection_pool import AsyncConnectionPool
File "C:\Python\Python36-32\lib\site-packages\httpcore\_async\connection_pool.py", line 4, in <module>
from .._backends.auto import AsyncLock, AsyncSemaphore, AutoBackend
File "C:\Python\Python36-32\lib\site-packages\httpcore\_backends\auto.py", line 4, in <module>
import sniffio
File "C:\Python\Python36-32\lib\site-packages\sniffio\__init__.py", line 10, in <module>
from ._impl import (
File "C:\Python\Python36-32\lib\site-packages\sniffio\_impl.py", line 1, in <module>
from contextvars import ContextVar
File "C:\Python\Python36-32\lib\site-packages\contextvars\__init__.py", line 4, in <module>
import immutables
File "C:\Python\Python36-32\lib\site-packages\immutables\__init__.py", line 18, in <module>
from ._protocols import MapKeys as MapKeys
File "C:\Python\Python36-32\lib\site-packages\immutables\_protocols.py", line 6, in <module>
from typing import NoReturn
ImportError: cannot import name 'NoReturn'
image
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'm using Python 3.6 in Ubuntu 16.04.
From this very simple program:
import pandas_datareader.data as web
import datetime
amzn = web.DataReader("AMZN", "yahoo", datetime(2000,1,1), datetime(2015,1,1))
I get this very impressive error list:
Traceback (most recent call last):
File "/SAT/time_series.py", line 1, in <module>
import pandas_datareader.data as web
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/google/daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/base.py", line 3, in <module>
import numpy as np
File "/anaconda/lib/python3.6/site-packages/numpy/__init__.py", line 146, in <module>
from . import add_newdocs
File "/anaconda/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/anaconda/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/anaconda/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/anaconda/lib/python3.6/site-packages/numpy/core/__init__.py", line 72, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/anaconda/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/anaconda/lib/python3.6/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/anaconda/lib/python3.6/unittest/main.py", line 4, in <module>
import argparse
File "/SAT/argparse.py", line 1
if len(sys.argv) > 1:
^
SyntaxError: invalid syntax
I've really now idea what is causing this error other than it's occurring when the program tries to import pandas_datareader.
I am new to the data_reader but I'm pretty sure the import command is syntactically correct.
Can anyone suggest what the problem is?
I think you have shadowed Python module argparse with your own /SAT/argparse.py.
/anaconda/lib/python3.6/unittest/main.py in line 4 tries to import argparse (the standard Python module), but your module (which has an error len(sys.argv) > 1:) jumps in first.
Try to rename /SAT/argparse.py to /SAT/my_argparse.py
PS try to name your own scripts and directories differently so that they don't shadow stardard Python modules
Try this:
import datetime
import pandas_datareader.data as web
amzn = web.DataReader("AMZN", "yahoo", datetime.datetime(2000,1,1), datetime.datetime(2015,1,1))
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 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.