5

I have read pip installing in global site-packages instead of virtualenv and made sure that everything is correct, i even reinstalled pip with easy_install within the virtaulenv.

What happens is strange. First it wont let me install a package without sudo... if I read the text output it tries to place it in the virtualenv path as expected.. I then use sudo and it works.

But if I try to install the package (in this case django-bootstrap3) then it states:

(env)kevin@g3:~/djangoP/work$ sudo pip install django-bootstrap3
Requirement already satisfied (use --upgrade to upgrade): django-bootstrap3 in /usr/local/lib/python3.4/dist-packages

which from what I understand means that it is installed outside of the virtualenv.

Not really sure what to do. Have read a few blogs and many people have variations of the issue but I cannot seem to find a solution for myself.

I am using Ubuntu 14, Python 2.7 and working in my home directory.

Any help would be great.

Thank you.

Community
  • 1
  • 1
Curious Lambda
  • 537
  • 2
  • 7
  • 21
  • PS the package cant be found in the site-packages folder hence again I have assume , although it my be assumed in ignorance that the pack is not install, for one django states it cant find the package at all. – Curious Lambda Sep 21 '15 at 15:57
  • Did you try to run `pip` directly from the virtualenv bin folder? – Ivan Sep 21 '15 at 16:00

3 Answers3

2

You should not install packages inside virtualenv using sudo.

It looks like a file permission problem to me. Either pip or virtualnev was installed with root privileges ant that is the reason why sudo is required when you try to install new packages inside virtualenv.

Check file permissions for executables you are using (virtualenv, pip).

dm@Z580:~$ which virtualenv
/usr/local/bin/virtualenv
dm@Z580:~$ ls -l /usr/local/bin/virtualenv
-rwxr-xr-x 1 root root 214 aug 18 21:20 /usr/local/bin/virtualenv

dm@Z580:~$ which pip
/usr/local/bin/pip
dm@Z580:~$ ls -l /usr/local/bin/pip
-rwxr-xr-x 1 root root 207 jun  3 15:33 /usr/local/bin/pip


dm@Z580:~$ virtualenv -p python2.7 testenv 
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in testenv/bin/python2.7
Also creating executable in testenv/bin/python
Installing setuptools, pip, wheel...done.
dm@Z580:~$ source testenv/bin/activate

(testenv)dm@Z580:~$ which pip
/home/dm/testenv/bin/pip
(testenv)dm@Z580:~$ ls -l /home/dm/testenv/bin/pip
-rwxrwxr-x 1 dm dm 219 sep 21 17:29 /home/dm/testenv/bin/pip
Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
2

You can simply use

./bin/pip

to install anything in your virtual environment. (I can't comment that's why I had to write here).

Kamal Singh
  • 531
  • 7
  • 17
1

I had the same problem today, It turned out that I had set manually PYTHONPATH variable in .bash_profile file so running in my shell after activating my virtual environment export PYTHONPATH= did the trick for me.

m.awad
  • 187
  • 2
  • 13