httplib2 invalid syntax error when attempting to import - python-2.7

I am attempting to set up an apache-beam pipeline and I keep getting the following error when I run my code
Traceback (most recent call last):
File "C:/Users/Student/PycharmProjects/Event-Log/Event-Pipeline.py", line 5, in <module>
import apache_beam as beam
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\apache_beam\__init__.py", line 78, in <module>
from apache_beam import io
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\apache_beam\io\__init__.py", line 34, in <module>
from apache_beam.io.gcp.bigquery import *
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\apache_beam\io\gcp\bigquery.py", line 114, in <module>
from apache_beam.internal.gcp import auth
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\apache_beam\internal\gcp\auth.py", line 26, in <module>
from oauth2client.client import GoogleCredentials
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\oauth2client\client.py", line 38, in <module>
from oauth2client import transport
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\oauth2client\transport.py", line 17, in <module>
import httplib2
File "C:\Users\Student\Anaconda3\envs\apache_beam\lib\site-packages\httplib2\__init__.py", line 352
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
I haven't edited anything in httplib2 at all and when I look at the code for that file, it seems like it should be correct but several expected statement errors appear for odd reasons. It also indicates that the in the first print line, it can't assign a literal. The offending code is below.
for h, v in msg.items():
print('%s:' % h, end=' ', file=self._fp)
if isinstance(v, Header):
print(v.encode(maxlinelen=self._maxheaderlen), file=self._fp)
else:
# Header's got lots of smarts, so use it.
header = Header(v, maxlinelen=self._maxheaderlen, charset='utf-8',
header_name=h)
print(header.encode(), file=self._fp)
# A blank line always separates headers from body
print(file=self._fp)

Related

libcublas issue - tensorflow

I am very new to tensorflow, struggling on its installation. I use ubuntu 16.04. I obviously installed the Nvidia dependencies.
Whenever I type in:
import tensorflow as tf
I get:
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
builtins.execfile(filename, *where)
File "/media/as/KINGSTON/SIEC NEURONOWA/NETWORK.py", line 3, in <module>
from keras.models import Sequential
File "/usr/local/lib/python2.7/dist-packages/keras/__init__.py", line 3, in <module>
from . import activations
File "/usr/local/lib/python2.7/dist-packages/keras/activations.py", line 4, in <module>
from . import backend as K
File "/usr/local/lib/python2.7/dist-packages/keras/backend/__init__.py", line 73, in <module>
from .tensorflow_backend import *
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1, in <module>
import tensorflow as tf
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/as/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I tried many solutions, but the effect remains the same. Many thanks for help!
I had this same problem when installing gputools in R. After hundreds of tries, the command which worked for me is:
sudo ln -s /usr/local/cuda/lib64/libcublas.so.8.0 /usr/lib/libcublas.so.8.0
OR
sudo ln -s /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/lib/libcublas.so.8.0

Issue with google cloud ml installation on local

I had followed the following instructions for setting up google-cloud-ml on LOCAL: MAC/LINUX
google-cloud-ml setup
But I am getting the following errors while verifying the setup with this command
curl https://raw.githubusercontent.com/GoogleCloudPlatform/cloudml-samples/master/tools/check_environment.py | python
Traceback (most recent call last):
File "", line 70, in
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/init.py", line 16, in
from google.cloud.ml.dataflow._analyzer import AnalyzeModel
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/init.py", line 22, in
from _ml_transforms import DeployVersion
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/_ml_transforms.py", line 24, in
import _ml_functions as ml_func
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/_ml_functions.py", line 25, in
from google.cloud.ml.io.coders import TrainingJobResult
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/io/init.py", line 21, in
from transforms import LoadFeatures
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/io/transforms.py", line 23, in
from google.cloud.ml.dataflow.io import tfrecordio
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/io/init.py", line 15, in
import tfrecordio
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/io/tfrecordio.py", line 16, in
_crc32c_fn = snappy._crc32c # pylint: disable=protected-access
AttributeError: 'module' object has no attribute '_crc32c'
Looks like there is some issue with dataflow library of google cloud.
I tried upgrading the dataflow library with the following command
pip install --upgrade google-api-python-client
but now, another error. Following is the stacktrace:
Traceback (most recent call last):
File "", line 70, in
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/init.py", line 16, in
from google.cloud.ml.dataflow._analyzer import AnalyzeModel
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/init.py", line 17, in
from _analyzer import AnalyzeModel
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/google/cloud/ml/dataflow/_analyzer.py", line 19, in
import apache_beam as beam
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/init.py", line 78, in
from apache_beam import io
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/io/init.py", line 21, in
from apache_beam.io.avroio import *
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/io/avroio.py", line 29, in
from apache_beam.io import filebasedsource
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/io/filebasedsource.py", line 32, in
from apache_beam.io import concat_source
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/io/concat_source.py", line 24, in
from apache_beam.io import iobase
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/io/iobase.py", line 853, in
from apache_beam.runners.dataflow.native_io.iobase import *
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/runners/init.py", line 23, in
from apache_beam.runners.dataflow_runner import DataflowRunner
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/runners/dataflow_runner.py", line 32, in
from apache_beam.internal import json_value
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apache_beam/internal/json_value.py", line 20, in
from apitools.base.py import extra_types
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apitools/base/py/init.py", line 23, in
from apitools.base.py.credentials_lib import *
File "/Users/pratyusha/miniconda2/envs/cloudml/lib/python2.7/site-packages/apitools/base/py/credentials_lib.py", line 50, in
from oauth2client import locked_file
This looks like a different version of 'snappy' is expected. Can you check which version of python-snappy you have installed?
You can do this by running:
pip freeze | grep python-snappy
It worked for me with version 0.5, which is the latest version. If you have an earlier version, try running:
pip install --upgrade python-snappy
(using 'sudo' or '--user' as necessary.)

Python, Networked programs from a book by Dr Charles Severance

I am a beginner in programming, started from Python. I learn by Dr Charles Severance materials. So in his book there is an example:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
for line in fhand:
print line.strip()
When I copy paste it to Python 2 version (I use PyCharm 5.0.4) there appears:
Traceback (most recent call last):
File "D:/Python4yk/temprehg111.py", line 2, in <module>
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 292, in open_http
import httplib
File "C:\Python27\lib\httplib.py", line 79, in <module>
import mimetools
File "C:\Python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
File "random.py", line 3, in <module>
integers
NameError: name 'line' is not defined
When I type another example, gets an error also. What is wrong? I don`t even write a program. I just copy paste an example. Asked Dr Chuck - still no answer.
Try this:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com')
for line in fhand:
print line.strip() # notice the indentation

PyDev: Can't compile after accidentally naming file after Python io.py

So I without thinking stupidly named a file io.py in my working directory. When I tried to compile I got a traceback error. Having realised what I'd done I renamed my file and updated references to it but I still get the following error:
Traceback (most recent call last):
File "C:\Users\Tom\workspace\Converter\get_file.py", line 9, in <module>
from scipy import complex_
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 70, in <module>
from numpy import show_config as show_numpy_config
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 185, in <module>
from . import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 46, in <module>
from numpy.testing import Tester
File "C:\Python27\lib\site-packages\numpy\testing\__init__.py", line 13, in <module>
from .utils import *
File "C:\Python27\lib\site-packages\numpy\testing\utils.py", line 15, in <module>
from tempfile import mkdtemp
File "C:\Python27\lib\tempfile.py", line 32, in <module>
import io as _io
File "C:\Users\Tom\workspace\Converter\io.py", line 1, in <module>
"""The io module provides the Python interfaces to stream handling. The
File "C:\Users\Tom\workspace\Converter\get_file.py", line 9, in <module>
from scipy import complex_
ImportError: cannot import name complex_
I have restarted PyDev to no avail. I have refreshed the interpreter to no avail.
I have followed the instructions found in this Python issue but that command returns the correct result on my machine.
Is tempfile.py a temporary file I can remove to resolve this issue?
I have found the solution. Stupidly simple but maybe worth leaving here for other newbies who fall into the same trap.
PyDev compiles the code into *.pyc files. When you update the references and rename the files these aren't immediately recompiled. Deleting the io.pyc file I had allowed compilation too run properly.
I found some more info on common pitfalls too.

python script and libGLEW related error (menpo.io API)

I am writing a python script in Ubuntu 14.04 that imports the menpo.io (API for deformable models) that results in the following error:
Traceback (most recent call last):
File "/home/Dropbox/pyFaceDepression/AAM_Menpo_final.py", line 1, in <module>
import menpo.io as mio
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/__init__.py", line 7, in <module>
import io
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/io/__init__.py", line 1, in <module>
from base import (import_auto, import_image, import_images,
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/io/base.py", line 815, in <module>
from menpo.io.extensions import (mesh_types, all_image_types,
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/io/extensions.py", line 2, in <module>
from menpo.io.landmark import (LM3Importer, LANImporter, LM2Importer,
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/io/landmark.py", line 9, in <module>
from menpo.shape import PointCloud
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/shape/__init__.py", line 2, in <module>
from menpo.shape.mesh import TriMesh, ColouredTriMesh, TexturedTriMesh
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/shape/mesh/__init__.py", line 2, in <module>
from .coloured import ColouredTriMesh
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/shape/mesh/coloured.py", line 3, in <module>
from menpo.rasterize import Rasterizable
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/rasterize/__init__.py", line 2, in <module>
from menpo.rasterize.opengl import GLRasterizer
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/menpo/rasterize/opengl.py", line 2, in <module>
from cyrasterize.base import CyRasterizerBase
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/cyrasterize/__init__.py", line 1, in <module>
from cyrasterize.base import CyRasterizer
File "/home/miniconda/envs/menpo/lib/python2.7/site-packages/cyrasterize/base.py", line 3, in <module>
from cyrasterize.glrasterizer import GLRasterizer
ImportError: libGLEW.so.#glew_version#: cannot open shared object file: No such file or directory
The library I import is called Menpo.io
Any ideas how to fix this ?
I have to apologise, this is actually totally my fault as I was trying to update some of our build scripts and accidentally released a broken build of GLEW. To fix this, you can run:
conda install -c menpo --force glew=1.10.0
Which should download and reinstall GLEW and hopefully fix this problem.
Please reply back if you have any problems at all!