Cannot import tensorflow in IPyhon3 - python-3.x

I am just pasting the output of my bash shell which could be quite explicit. Running IPython:
petrux#orion:~/Projects/dket$ ipython
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import tensorflow as tf
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
/home/petrux/.local/lib/python3.5/site-packages/tensorflow/__init__.py in <module>()
22
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import
26
/home/petrux/.local/lib/python3.5/site-packages/tensorflow/python/__init__.py in <module>()
73
74 # Protocol buffers
---> 75 from tensorflow.core.framework.graph_pb2 import *
76 from tensorflow.core.framework.node_def_pb2 import *
77 from tensorflow.core.framework.summary_pb2 import *
/home/petrux/.local/lib/python3.5/site-packages/tensorflow/core/framework/graph_pb2.py in <module>()
4 import sys
5 _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
----> 6 from google.protobuf import descriptor as _descriptor
7 from google.protobuf import message as _message
8 from google.protobuf import reflection as _reflection
ImportError: No module named 'google.protobuf'; 'google' is not a package
while running the regular python interpreter:
petrux#orion:~/Projects/dket$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
I am running Ubuntu 16.04 as OS.
Thanks in advance.

Related

unable to import pytorch-lightning

I installed pytorch-lightning using pip, and I'm running on Mac.
I tried:
! pip install pytorch-lightning --upgrade
! pip install pytorch-lightning-bolts
(finished successfully)
and then:
import pytorch_lightning as pl
and what I get is:
--
-------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-f3b4217dcea1> in <module>
7 from torchvision.datasets import MNIST
8 from torchvision import transforms
----> 9 import pytorch_lightning as pl
10 from pytorch_lightning.metrics.functional import accuracy
11 tmpdir = os.getcwd()
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/__init__.py in <module>
60 # We are not importing the rest of the lightning during the build process, as it may not be compiled yet
61 else:
---> 62 from pytorch_lightning import metrics
63 from pytorch_lightning.callbacks import Callback
64 from pytorch_lightning.core import LightningDataModule, LightningModule
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/__init__.py in <module>
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from pytorch_lightning.metrics.classification import ( # noqa: F401
15 Accuracy,
16 AUC,
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/__init__.py in <module>
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from pytorch_lightning.metrics.classification.accuracy import Accuracy # noqa: F401
15 from pytorch_lightning.metrics.classification.auc import AUC # noqa: F401
16 from pytorch_lightning.metrics.classification.auroc import AUROC # noqa: F401
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/accuracy.py in <module>
16 import torch
17
---> 18 from pytorch_lightning.metrics.functional.accuracy import _accuracy_compute, _accuracy_update
19 from pytorch_lightning.metrics.metric import Metric
20
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/functional/__init__.py in <module>
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from pytorch_lightning.metrics.functional.accuracy import accuracy # noqa: F401
15 from pytorch_lightning.metrics.functional.auc import auc # noqa: F401
16 from pytorch_lightning.metrics.functional.auroc import auroc # noqa: F401
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/functional/accuracy.py in <module>
16 import torch
17
---> 18 from pytorch_lightning.metrics.classification.helpers import _input_format_classification, DataType
19
20
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/helpers.py in <module>
17 import torch
18
---> 19 from pytorch_lightning.metrics.utils import select_topk, to_onehot
20 from pytorch_lightning.utilities import LightningEnum
21
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/metrics/utils.py in <module>
16 import torch
17
---> 18 from pytorch_lightning.utilities import rank_zero_warn
19
20 METRIC_EPS = 1e-6
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/utilities/__init__.py in <module>
16 import numpy
17
---> 18 from pytorch_lightning.utilities.apply_func import move_data_to_device # noqa: F401
19 from pytorch_lightning.utilities.distributed import ( # noqa: F401
20 AllGatherGrad,
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/utilities/apply_func.py in <module>
23
24 from pytorch_lightning.utilities.exceptions import MisconfigurationException
---> 25 from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE
26
27 if _TORCHTEXT_AVAILABLE:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/utilities/imports.py in <module>
54 _TORCH_GREATER_EQUAL_1_7 = _compare_version("torch", operator.ge, "1.7.0")
55 _TORCH_QUANTIZE_AVAILABLE = bool([eg for eg in torch.backends.quantized.supported_engines if eg != 'none'])
---> 56 _APEX_AVAILABLE = _module_available("apex.amp")
57 _BOLTS_AVAILABLE = _module_available('pl_bolts')
58 _DEEPSPEED_AVAILABLE = not _IS_WINDOWS and _module_available('deepspeed')
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytorch_lightning/utilities/imports.py in _module_available(module_path)
32 """
33 try:
---> 34 return find_spec(module_path) is not None
35 except AttributeError:
36 # Python 3.6
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/util.py in find_spec(name, package)
92 parent_name = fullname.rpartition('.')[0]
93 if parent_name:
---> 94 parent = __import__(parent_name, fromlist=['__path__'])
95 try:
96 parent_path = parent.__path__
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/apex/__init__.py in <module>
11 ISessionFactory)
12 from pyramid.security import NO_PERMISSION_REQUIRED
---> 13 from pyramid.session import UnencryptedCookieSessionFactoryConfig
14 from pyramid.settings import asbool
15
ImportError: cannot import name 'UnencryptedCookieSessionFactoryConfig' from 'pyramid.session' (unknown location
I guess this is an outdated issue as we have cut out TorchMetrics to a standalone package. Please, check out the latest PytorchLightning.
Try installing it from the GitHub repository first before importing it in the notebook.
Run the following command in the Notebook:
!pip install git+https://github.com/PyTorchLightning/pytorch-lightning

Trouble importing modules into ipython

On a freshly installed Windows 10 machine, I installed the newest 64bit version of anaconda. Now when I try importing modules into ipython, I get errors. Some sample errors are reproduced below.
I am new to Python and Programming, so would appreciate a bit of help. This is a brand new Lenovo laptop, so there's no scope for any Python version conflict etc. (since nothing was installed on it earlier).
In [1]: import sklearn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn
C:\Software\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
74 else:
75 from . import __check_build
---> 76 from .base import clone
77 from .utils._show_versions import show_versions
78
C:\Software\anaconda3\lib\site-packages\sklearn\base.py in <module>
11 import re
12
---> 13 import numpy as np
14
15 from . import __version__
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
C:\Software\anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
136 # cbook must import matplotlib only within function
137 # definitions, so it is safe to import from it here.
--> 138 from . import cbook, rcsetup
139 from matplotlib.cbook import (
140 MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)
C:\Software\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in <module>
29 from weakref import WeakMethod
30
---> 31 import numpy as np
32
33 import matplotlib
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [3]: import pystan
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-ca8618bb8e4a> in <module>
----> 1 import pystan
ModuleNotFoundError: No module named 'pystan'
In [4]:
After a lot of google searching, I found a few sites that touch upon some closely related issues (ex. https://github.com/stan-dev/pystan/issues/520). It so happens that one needs to add some anaconda directroties to the Windows path. I added anaconda/Library/bin, anaconda/Scripts to the path. Now everything is working as expected.

Problem in importing Autograph in Tensorflow

I have installed Tensorflow (1.13.0) using conda as follows:
conda install -c anaconda tensorflow
on my Win64 machine with python 3.6 in my conda environment. I am able to import tensorflow from my Jupyter notebook. In my project, I need to use AutoGraph. However, when I try to import autograph, then I get this error - ImportError: cannot import name 'deprecated_endpoints'
I am able to verify that autograph folder exists in my tensorflow package "..\py36\Lib\site-packages\tensorflow\python\autograph". However, the below code statement gives that Import Error.
import tensorflow.python.autograph as ag
Complete error trace:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-13-9224a57db065> in <module>
1 import tensorflow as tf
----> 2 import tensorflow.python.autograph as ag
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\__init__.py in <module>
33
34 # TODO(mdan): Bring only the relevant symbols to the top level.
---> 35 from tensorflow.python.autograph import operators
36 from tensorflow.python.autograph import utils
37 from tensorflow.python.autograph.core.converter import ConversionOptions
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\__init__.py in <module>
38 from __future__ import print_function
39
---> 40 from tensorflow.python.autograph.operators.control_flow import for_stmt
41 from tensorflow.python.autograph.operators.control_flow import if_stmt
42 from tensorflow.python.autograph.operators.control_flow import while_stmt
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py in <module>
19 from __future__ import print_function
20
---> 21 from tensorflow.python.autograph.operators import py_builtins
22 from tensorflow.python.data.ops import dataset_ops
23 from tensorflow.python.framework import tensor_util
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\py_builtins.py in <module>
24 import six
25
---> 26 from tensorflow.python.autograph.utils import py_func
27 from tensorflow.python.autograph.utils import tensors
28 from tensorflow.python.framework import constant_op
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\utils\__init__.py in <module>
22 from tensorflow.python.autograph.utils.misc import alias_tensors
23 from tensorflow.python.autograph.utils.py_func import wrap_py_func
---> 24 from tensorflow.python.autograph.utils.tensor_list import dynamic_list_append
25 from tensorflow.python.autograph.utils.testing import fake_tf
26 from tensorflow.python.autograph.utils.type_check import is_tensor
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\utils\tensor_list.py in <module>
20
21 from tensorflow.python.framework import ops
---> 22 from tensorflow.python.ops import list_ops
23 from tensorflow.python.ops import tensor_array_ops
24
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\ops\list_ops.py in <module>
24 from tensorflow.python.framework import tensor_shape
25 from tensorflow.python.ops import array_ops
---> 26 from tensorflow.python.ops import gen_list_ops
27 # go/tf-wildcard-import
28 # pylint: disable=wildcard-import
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\ops\gen_list_ops.py in <module>
21 from tensorflow.python.framework import ops as _ops
22 from tensorflow.python.framework import op_def_library as _op_def_library
---> 23 from tensorflow.python.util.deprecation import deprecated_endpoints
24 from tensorflow.python.util import dispatch as _dispatch
25 from tensorflow.python.util.tf_export import tf_export
ImportError: cannot import name 'deprecated_endpoints'
---------------------------------------------------------------------------
How should I fix it?

Why I can't import pdfplumber

When I was trying to import pdfplumber, it gives me error.
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import pdfplumber
ImportError Traceback (most recent call last)
in ()
----> 1 import pdfplumber
/anaconda3/lib/python3.6/site-packages/pdfplumber/init.py in ()
---->
1 from pdfplumber.pdf import PDF
2 import pdfplumber.utils
3 import pdfminer
4 import pdfminer.pdftypes
5 from ._version import __version__
/anaconda3/lib/python3.6/site-packages/pdfplumber/pdf.py in ()
4
5 from pdfminer.pdfparser import PDFParser
----> 6 from pdfminer.pdfdocument import PDFDocument
7 from pdfminer.pdfpage import PDFPage
8 from pdfminer.pdfinterp import PDFResourceManager,
PDFPageInterpreter
/anaconda3/lib/python3.6/site-packages/pdfminer/pdfdocument.py in ()
24 from .pdftypes import PDFTypeError
25 from .pdftypes import PDFStream
---> 26 from .pdftypes import PDFObjectNotFound
27 from .pdftypes import decipher_all
28 from .pdftypes import int_value
ImportError: cannot import name 'PDFObjectNotFound'
Any solutions?
Thanks!
You should install imagemagick as guided here
Restart after installed and then, import pdfplumber again

ImportError: DLL load failed: The specified procedure could not be found. (import sklearn)

When I import sklearn, it throws this ImportError(DLL load failed: The specified procedure could not be found.)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>()
----> 1 import sklearn
~\Anaconda3\lib\site-packages\sklearn\__init__.py in <module>()
62 else:
63 from . import __check_build
---> 64 from .base import clone
65 from .utils._show_versions import show_versions
66
~\Anaconda3\lib\site-packages\sklearn\base.py in <module>()
11 from scipy import sparse
12 from .externals import six
---> 13 from .utils.fixes import signature
14 from . import __version__
15
~\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>()
11
12 from .murmurhash import murmurhash3_32
---> 13 from .validation import (as_float_array,
14 assert_all_finite,
15 check_random_state, column_or_1d, check_array,
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>()
20
21 from ..externals import six
---> 22 from ..utils.fixes import signature
23 from .. import get_config as _get_config
24 from ..exceptions import NonBLASDotWarning
~\Anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>()
81 return stats.boxcox(x, lmbda)
82 else:
---> 83 from scipy.special import boxcox # noqa
84
85
~\Anaconda3\lib\site-packages\scipy\special\__init__.py in <module>()
638 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
639
--> 640 from ._ufuncs import *
641
642 from .basic import *
ImportError: DLL load failed: The specified procedure could not be found.
If you already have a working installation of numpy and scipy, then do this:
pip install -U scikit-learn
otherwise:
conda install scikit-learn
finally check for updates:
conda update pip

Resources