1

Here I am trying to install some module(consider numpy) in virtualenv environment cv. I trying install it with,

sudo pip3 install numpy

it gets inside my normal environment but not the one i created using virtualenv. I keep getting

File "sample.py", line 1, in <module>
    import numpy as np
ImportError: No module named 'numpy'

It works fine in my normal environment. The installed files exist under my /usr/local/lib/python3.5/dist-packages but couldn't find it under .virtualenvs/cv/lib/python3.5/site-packages. I am not sure what I am doing wrong.

I refered couple similar problems and tried it but none worked. I even tried deactivating the env and creating a new one. Let me know if you need any more info. Thanks in advance.

Note: I did activate the environment. When I tried installing again, it says,

Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages

It is checking in the normal environment lib folder, not in the virtualenv.

arvind
  • 778
  • 1
  • 9
  • 16
  • Did you activate the virtual environment then install `numpy`? – Arpit Solanki Feb 15 '18 at 08:19
  • of course, I did. – arvind Feb 15 '18 at 08:22
  • Possible duplicate of [ImportError: No module named 'pandas' (inside virtualenv)](https://stackoverflow.com/questions/45666097/importerror-no-module-named-pandas-inside-virtualenv) – phd Feb 15 '18 at 16:07
  • 1
    Don't use `sudo` in a virtualenv — `sudo pip install` installs packages into global `site-packages`, not in virtualenv. – phd Feb 15 '18 at 16:07

3 Answers3

1

I had this same problem, and the issue was that I had python referring to python 2.7. When you create the virtualenv, the default python interpreter is /usr/bin/python. If you then install with pip3 it tries to install in the default python 3 location. The solution was to specify:

virtualenv <venv-name> --py /usr/bin/python3
Amit Hochman
  • 111
  • 3
0

Did you run the pip install command inside an activated virtualenv ?

This link tells you how: https://packaging.python.org/guides/installing-using-pip-and-virtualenv/

You can also refer to: How to leave/exit/deactivate a python virtualenv?

Amol
  • 1
0
source .virtualenvs/cv/bin/activate

Now try installing libraries with pip.

When you are done working on this project deactivate the virtualenvs with deactivate command.

MiniGunnR
  • 5,590
  • 8
  • 42
  • 66