Why python3.5 links python2.7's numpy? - python

Update the problem:
I use
sudo python3
>>import numpy
It works!
And I use the suggestion of below comments :
delete the /usr/local/lib/python2.7/site-packages in path.
and the problem solved!
======== the old problem ===========
I'm using Mac OS El Capitan.
The Python2.7 is the default version; python3.5 is installed from the official site python3.5 for mac.
I have already installed numpy in python2.7. Now I need to install numpy in python3.5.
I use:
pip3 install numpy
which return
"Requirement already satisfied (use --upgrade to upgrade):
numpy in /usr/local/lib/python2.7/site-packages"
and when I run
python3
>>import numpy
in python3
it outputs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so
Expected in: flat namespace
in /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so
It link the 2.7 package.. and show error.
(Similar Problem happens when I install scipy and sklearn)
How to solve the problem?

I ran into the same problem. Uninstalling numpy using pip3, and reinstalling, fixed the issue.
pip3 uninstall numpy
pip3 install numpy

An easy way to avoid this is to install all these modules using anaconda.
https://www.continuum.io/downloads
It will avoid you the headache of installing manually.

Related

Astropy complaining about Numpy version

I just updated Astropy to version 3.1.2. Now I'm trying to run a (previously working) Python 3 script that uses it, and it's failing with the following message:
Traceback (most recent call last):
File "./body-local.py", line 3, in <module>
from astropy.time import Time
File "/home/jimc/.local/lib/python3.6/site-packages/astropy/__init__.py", line 121, in <module>
_check_numpy()
File "/home/jimc/.local/lib/python3.6/site-packages/astropy/__init__.py", line 115, in _check_numpy
raise ImportError(msg)
ImportError: Numpy version 1.13.0 or later must be installed to use Astropy
My installed Numpy version is 1.16.2.
I had a bad Numpy installation. The solution was to repeatedly uninstall Numpy, as regular user and root, until no more installations were found, then reinstall:
pip3 uninstall numpy
sudo pip3 uninstall numpy
^ Until no more remain, then:
sudo pip3 install numpy

Error importing tensorflow in Python 3 on Ubuntu 16.04 SyntaxError: l.append("%s=%s" % (attr, `value`))

I have python 3.5 installed on my Linux Mint (Ubuntu 16.04 Xenial)
I also had installed protobuf installed using pip3 install protobuf
I installed tensorflow using pip3 install tensorflow
Then I tried to import tensorflow in python 3 it failed with error presented below:
Traceback (most recent call last):
File "/home/abdullah/face_recognition/tensorflow_test.py", line 1, in <module>
import tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 83, in <module>
from tensorflow.python.estimator import estimator_lib as estimator
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator_lib.py", line 35, in <module>
from tensorflow.python.estimator.inputs import inputs
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/inputs.py", line 22, in <module>
from tensorflow.python.estimator.inputs.numpy_io import numpy_input_fn
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/numpy_io.py", line 22, in <module>
from tensorflow.python.estimator.inputs.queues import feeding_functions
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/queues/feeding_functions.py", line 40, in <module>
import pandas as pd
File "/usr/local/lib/python3.5/dist-packages/pandas/__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "/usr/local/lib/python3.5/dist-packages/pandas/compat/__init__.py", line 361, in <module>
from dateutil import parser as _date_parser
File "/usr/local/lib/python3.5/dist-packages/dateutil/parser.py", line 158
l.append("%s=%s" % (attr, `value`))
^
SyntaxError: invalid syntax
Consulting through many questions posted on SO and other forums, I tried uninstalling protobuf then I encountered following error.
Traceback (most recent call last):
File "/home/abdullah/face_recognition/tensorflow_test.py", line 1, in <module>
import tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
ImportError: No module named 'google.protobuf'
At the moment I'm just a beginner for all of this. I don't why protobuf is required why do all this hassle? I just wanted to get tensorflow installed on my system and try to learn something.
I was also facing the same problem. The problem I think is this is using pandas from system(apt-get) repository which is not compatible with other libraries. Updating pandas do the trick.
pip3 install --upgrade pandas
Also in your case, if only doing above fails, you can also try to reinstall tensorflow and protobuf with upgrade option.
pip3 install --upgrade protobuf
pip3 install --upgrade tensorflow
I just installed TensorFlow on my system today (Ubuntu 16.04 LTS) using VirtualEnv.
Did you run$ sudo apt-get install python3-pip python3-dev
If so, then try $ pip3 install -upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.0-cp35-cp35m-linux_x86_64.whl
Worst comes to worse, you could simply uninstall TensorFlow using $ sudo pip3 uninstall tensorflow and then try reinstalling to see if it corrects any errors.

pycrypto : No module named strxor

I got this error :
Traceback (most recent call last):
File "test.py", line 8, in <module>
from Crypto.Cipher import PKCS1_OAEP
File "C:\Users\Mokhles\Downloads\google-api-python-client-1.5.3\Crypto \Cipher\PKCS1_OAEP.py", line 57, in <module>
import Crypto.Signature.PKCS1_PSS
File "C:\Users\Mokhles\Downloads\google-api-python-client-1.5.3\Crypto \Signature\PKCS1_PSS.py", line 74, in <module>
from Crypto.Util.strxor import strxor
ImportError: No module named strxor
any idea how to solve it?
ENV:
-windows 10
-python 2.7
It looks like you're simply copied pyCrypto into your project. PyCrypto is library which depends on some native library/code (like libtomcrypt). You have to install it properly. You can do this for example through pip:
pip2 install pycrypto
or
pip3 install pycrypto
depending on which Python version you want to make it available.
try conda install pydotplus (may need to install tqdm first)

Tensorflow pip built from source fails on 'import tensorflow'

Built tensorflow 0.7 from source on Ubuntu 15.10, Cuda 7.5, cudnn 4.0, python 2.7. Bazel build and pip package generation OK. pip install ok. Python script "import tensorflow" fails:
Traceback (most recent call last):
File "/home/keith/Desktop/tf1.py", line 8, in <module>
import tensorflow as tf
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 35, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module>
serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"z\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x12\x14\n\x0cunknown_rank\x18\x03 \x01(\x08\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tB/\n\x18org.tensorflow.frameworkB\x11TensorShapeProtosP\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
Any thoughts?
Thanks
This does look like a protobuf library versioning error. There's a long thread on similar issues here:
https://github.com/tensorflow/tensorflow/issues/11
Towards the end there are some suggested solutions that might help.
I succeed in running TensorFlow 0.7 on a manjaro linux laptop using cuda acceleration by running python with optirun:
$optirun python
However, I had problem with protobuf and I had to uninstall/reinstall previous version of protobuf and tensorflow with pip. http://bit.ly/1RHApU5
This is because of protobuf version conflict:
for me i had python-protobuf v2.6.1 installed from apt-get package manager
and while installing tensorflow it installed protobuf v3.3.0 from pip manager
so i uninstalled both:
sudo pip uninstall protobuf
sudo apt-get remove python-protobuf
Reinstalled using pip and it solved the issue!!!
sudo pip install protobuf
Hope this helps..

numpy.core.multiarray failed to import

I used the following command to know the numpy version I am using
pip show numpy
output shown below
---
Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages
Requires:
However when I am running matplotlib, I got a error as
RuntimeError: module compiled against API version a but this version of numpy is 9
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/usr/local/lib/python2.7/dist-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
I tried to upgrade numpy,
pip install numpy --upgrade
it shows to be installed successfully, but numpy still shows to be 1.8.2 and error continues to exist when running matplotlib.
I thought to uninstall numpy and reinstall it, the system gives the message saying
Not uninstalling numpy at /usr/lib/python2.7/dist-packages, owned by OS
how to solve it ?
any idea about
RuntimeError: module compiled against API version a but this version
of numpy is 9
How can I upgrade numpy? might be working for you. IN that case it was a path problem:
RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
Solution:
Check the path
import numpy
print numpy.__path__
and manually delete it using rm
I also had the same problem until I came across this Issue on Pytorch github repository. This command worked perfectly for me:
pip install numpy -I
It is also mentioned there that pip install numpy --upgrade is not working(don't know why). You can check the above mentioned link.
I had a similar problem with numpy when running torch. I tried uninstalling numpy and installing it using -U but it didn't work. After some search, I found this link and it solved my problem. It says you should change your numpy version.
pip uninstall numpy
pip install numpy==1.19.3
The answer is probably simple.
Just add
import numpy.core.multiarray
before the
import cv2
statement.
It worked fine for me.
My problem is solved using the old version of numpy. The solution is to use numpy 1.19.3.
pip install numpy==1.19.3
Credit: https://stackoverflow.com/a/64730012
Installing the previous version of NumPy, 1.19.3 should fix this.
python -m pip install numpy==1.19.3

Categories

Resources