import apache_beam metaclass conflict - python-2.7

When I try to import apache beam I get the following error.
>>> import apache_beam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/toor/pfff/local/lib/python2.7/site-packages/apache_beam/__init__.py", line 78, in <module>
from apache_beam import io
File "/home/toor/pfff/local/lib/python2.7/site-packages/apache_beam/io/__init__.py", line 21, in <module>
...
from apitools.base.protorpclite import messages
File "/home/toor/pfff/local/lib/python2.7/site-packages/apitools/base/protorpclite/messages.py", line 1165, in <module>
class Field(six.with_metaclass(_FieldMeta, object)):
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
I'm working in a new virtual environment in which I have installed apache_beam by installing google-cloud-dataflow with pip as I need the version that is able to run on google cloud platform.
pip install google-cloud-dataflow
I have no idea how to solve this error. For completeness, I'm using python 2.7.12 on bash on ubuntu on Windows. My colleague had the same error when running it on bash on ubuntu on Windows, while directly running on Windows is working fine.
The installed versions of the packages are:
>>> pip freeze
apache-beam==2.1.0
avro==1.8.2
cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
crcmod==1.7
dill==0.2.6
enum34==1.1.6
funcsigs==1.0.2
future==0.16.0
futures==3.1.1
gapic-google-cloud-pubsub-v1==0.15.4
google-apitools==0.5.11
google-auth==1.1.0
google-auth-httplib2==0.0.2
google-cloud-bigquery==0.25.0
google-cloud-core==0.25.0
google-cloud-dataflow==2.1.0
google-cloud-pubsub==0.26.0
google-gax==0.15.15
googleapis-common-protos==1.5.2
googledatastore==7.0.1
grpc-google-iam-v1==0.11.3
grpcio==1.6.0
httplib2==0.9.2
idna==2.6
mock==2.0.0
oauth2client==3.0.0
pbr==3.1.1
pkg-resources==0.0.0
ply==3.8
proto-google-cloud-datastore-v1==0.90.4
proto-google-cloud-pubsub-v1==0.15.4
protobuf==3.3.0
pyasn1==0.3.5
pyasn1-modules==0.1.4
PyYAML==3.12
requests==2.18.4
rsa==3.4.2
six==1.11.0
urllib3==1.22

Downgrade six to version 1.10.0
pip install six==1.10.0

Related

Try to get variable type on python3 on macOS and it show the below error

Traceback (most recent call last): File "/Users/kane/study/python/basicDataStructure/liner_data_structure.py", line 2, in <module> from turtle import clear File "/usr/local/Cellar/python#3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 107, in <module> import tkinter as TK File "/usr/local/Cellar/python#3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module> import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter'
Note Please note that, I didn't use anything regarding tkinter. I only created a variable and checked its type.
I have found the answer at the link
brew install python-tk
You will have to firstly import it on the os device!
Run these in your terminal
python3 get-pip.py
Pip install turtle
Pip install tkinter

how to install numba and link to llvm & llvmlite to import it in Python27

When I am trying to run python file .py that uses numba it gives me the below error
Traceback (most recent call last):
File "C:\Myfile.py", line 16, in <module>
import myfile2 as m
File "C:\myfile2.py", line 8, in <module>
import numba
File "C:\Python27\lib\site-packages\numba\__init__.py", line 9, in <module>
from . import config, errors, runtests, types
File "C:\Python27\lib\site-packages\numba\config.py", line 11, in <module>
import llvmlite.binding as ll
File "C:\Python27\lib\site-packages\llvmlite\binding\__init__.py", line 6, in <module>
from .dylib import *
File "C:\Python27\lib\site-packages\llvmlite\binding\dylib.py", line 4, in <module>
from . import ffi
File "C:\Python27\lib\site-packages\llvmlite\binding\ffi.py", line 50, in <module>
raise e
WindowsError: [Error 126] The specified module could not be found
I've tried to isntall numba from command propmt as below :
pip install numba
but it gives me a message that it already exists before
Requirements already satisfied...........etc
so could anyone help me to fix this error ? also How to install numba and link it with llvm and llvmlite ?
I've uninstall the python and re-install it again
and install the below packages in order
pip install scikit_learn
pip install numby+mkl
pip install scipy
pip install numba
pip install matplotlib
also I've installed mini conda and it is working fine as well

ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

Possible duplicate of this question.
I have a gpu account to whom I connect through putty (ssh login). I have created a virtualenv there and I am installing tenorflow through pip for gpu. Everything works fine, when I run command
$ pip list
following list is being shown:
backports.weakref (1.0rc1)
bleach (1.5.0)
funcsigs (1.0.2)
html5lib (0.9999999)
Markdown (2.6.8)
mock (2.0.0)
numpy (1.13.1)
olefile (0.44)
pbr (3.1.1)
Pillow (4.2.1)
pip (9.0.1)
protobuf (3.3.0)
setuptools (36.0.1)
six (1.10.0)
tensorflow-gpu (1.2.1)
Werkzeug (0.12.2)
wheel (0.29.0)
But when I run:
$ python
>>> import tensorflow
It shows the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/nauman/junaid/final/test/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/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
<module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/nauman/junaid/final/test/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: libcusolver.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 have also set my environment variables like this:
export CUDA_HOME=/opt/cuda
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64"
Moreover, I found that libcusolver.so.8.0 is not there, while libcusolver.so.7.5
is there in cuda/lib64/.
Somehow tensorflow is finding wrong file or I ain't know nothing.
Any help would be appreciated as I am new to all this stuff.
Python version: 2.7
OS: Linux
This may be connected to the incorrect linking of your libraries.
Simply run sudo ldconfig /usr/local/cuda/lib64. It solved for me.
If you need to know more: ldconfig man page.
I solved the issue. Actually I have cuda 7.5 installed and I was installing latest tensorflow version which probably support cuda 8.0.
So I downgraded.
pip install --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
If you installed tensorflow-gpu by using pip with prebuilt .whl, the cuda version were fixed. As far as I know, starting 0.11.0rc1, all the prebuilt packages are now built for cuda 8. So there are two ways to solve the problem:
install cuda 8 for the prebuilt packages tensorflow-gpu >= 0.11.orc1
keep cuda 7.5 stay, then build tensorflow-gpu from source code
If you are using cuda-9.0 try sudo apt install nvidia-cuda-dev (if you are using an Ubuntu distribution)

How to import scikit-learn in python virtual environment?

The Problem
I'm trying to use scikit-learn on a virtual environment and I cannot get it to run.
So, for example, I go to a project folder and install NumPy, SciPy, and scikit-learn
virtualenv venv
source venv/bin/activate
pip install numpy
pip install scipy
pip install scikit-learn
Then I open python and try to import each of them.
import numpy
import scipy
import sklearn
NumPy and SciPy import fine, but when I try to import I get an error saying Library not loaded: #rpath/./libgfortran.3.dylib.
Is there something I'm missing in the installation?
Full error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/validation.py", line 16, in <module>
from ..utils.fixes import signature
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/fixes.py", line 324, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/__init__.py", line 109, in <module>
from .isolve import *
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
from . import _iterative
ImportError: dlopen(/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: #rpath/./libgfortran.3.dylib
Referenced from: /Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so
Reason: image not found
EDIT:
this was some troubleshooting to host a Heroku app using sklearn.
I would strongly recommend against using virtual environments for NumPy/SciPy/Scikit-learn and other packages which include compiled code. Virtual environments deal with pure Python dependencies reasonably well, but for compiled extensions with dependencies outside Python, they can fail in unexpected ways (as you have seen).
If you want to manage multiple environments with different versions of Python packages including compiled extensions, the best tool out there is probably conda, and in particular conda environments.
With it, you can run the following:
$ conda create -n myenv python=3.4 numpy scipy scikit-learn
$ source activate myenv
(myenv) $ python
Python 3.4.3
>>> import sklearn
and you'll be good to go.

After installing factory_boy, imports are not recognized.

Pip install factory_boy seems to install the package without problems. Running pip freeze shows me:
Django==1.7
dj-database-url==0.3.0
dj-static==0.0.6
django-toolbelt==0.0.1
factory-boy==2.4.1
gunicorn==19.1.1
static3==0.5.1
However, when I edit my tests to put import factory or import factory.django... I get the result:
Traceback (most recent call last):
File "C:\Python27\lib\unittest\loader.py", line 252, in _find_tests
module = self._get_module_from_name(name)
File "C:\Python27\lib\unittest\loader.py", line 230, in _get_module_from_name
__import__(name)
File "C:\Users\Jeff\Projects\gamematch2\eventbook\tests.py", line 6, in <modul
e>
import factory.django
ImportError: No module named factory.django
I've followed the advice in:
Trouble installing factory_boy with pip
with no results.
Not sure how to proceed, any help would be appreciated.
Appears to be a problem with my virtual environment. Exiting virtualenv, installing factory_boy again, and then running manage.py test again works successfully. Not fully solved, but at least I have a work around.