Travis D
Travis D

Reputation: 317

Amazon EC2 virtualenv: pip says it installed numpy but python can't find it

I've researched this question pretty thoroughly and can't seem to find an answer.

I'm running a virtualenv and am trying to install numpy, on EC2 using Python 2.7. Yes, I have activated the virtualenv.

(dev)[ec2-user site]$ pip --no-cache-dir install numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/c0/e7/08f059a00367fd613e4f2875a16c70b6237268a1d6d166c6d36acada8301/numpy-1.14.3-cp27-cp27mu-manylinux1_x86_64.whl (12.1MB)
    100% |████████████████████████████████| 12.1MB 87.8MB/s
Installing collected packages: numpy
Successfully installed numpy-1.14.3

But, immediately after:

(dev)[ec2-user site]$ python -c "import numpy; print numpy.__version__"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named numpy

I've upgraded pip. The numpy package does appear to be installed:

(dev)[ec2-user site]$ find ~/ -name numpy
/home/ec2-user/dev/lib64/python2.7/dist-packages/pandas/compat/numpy
/home/ec2-user/dev/lib64/python2.7/dist-packages/numpy
/home/ec2-user/dev/lib64/python2.7/dist-packages/numpy/core/include/numpy

numpy does not appear in pip freeze

> pip freeze | egrep numpy
>

So - I cannot uninstall numpy to reinstall it. I have tried manually deleting the numpy directories I've listed above and reinstalling, but no dice. Yes, I have gcc installed, and this appears to be the only package that I have problems with.

I do not want to yum install python27-numpy because I want this to be contained in the virtualenv.

> which python
~/dev/bin/python
> python -V
Python 2.7.12

Picking a random python package, let's say......, ansible, installing it, seems to work without issue:

> pip install ansible > /dev/null
> python -c "import ansible; print ansible.__version__"
2.5.4

So the issue appears to be isolated to numpy.

Upvotes: 1

Views: 524

Answers (1)

Travis D
Travis D

Reputation: 317

Ok - answered my own question:

pip seems to install numpy here:

/home/ec2-user/dev/lib64/python2.7/

but python isn't loading this as path as a library path.

Solution:

mv ~/dev/lib64/python2.7/dist-packages/numpy ~/dev/lib/python2.7/dist-packages/numpy

Hopefully this helps someone out!

Upvotes: 1

Related Questions