Custom Search
Showing posts with label virtualenv. Show all posts
Showing posts with label virtualenv. Show all posts

Thursday, January 5, 2017

Howto force sudo pip install module in virtualenv which created with sudo

$source venv/bin/activate

(venv)$sudo venv/bin/pip install django

(venv)$python
>>>import django


Friday, December 9, 2016

How to fix python pip not installing package to virtualenv site-packages

1)
(myenv) saju@ubuntu:~$ sudo pip install -t /home/saju/myenv/lib/python2.7/site-packages django-localflavor

Use -t option

2)
(myenv) saju@ubuntu:~$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import localflavor

How to fix python pip installing package in global dist-packages instead of virtualenv

1)
(myenv) saju@ubuntu:~$ sudo pip install -t /home/saju/myenv/lib/python2.7/site-packages django-localflavor

Use -t option

2)
(myenv) saju@ubuntu:~$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import localflavor

How to pip install python package into a specific directory

1)
(myenv) saju@ubuntu:~$ sudo pip install -t /home/saju/myenv/lib/python2.7/site-packages django-localflavor

Use -t option

2)
(myenv) saju@ubuntu:~$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import localflavor

Monday, February 17, 2014

How to install python packages in virtualenv using sudo

How to install python packages in virtualenv using sudo

Issue
=====

a)
I created a virtualenv ".venv" using following command in /opt
#cd /opt
#sudo virtualenv .venv
#source .venv/bin/activate
#sudo easy_install python-keystoneclient

But package not installing in virtualenv ".venv" instead it pointing to
/usr/local/lib/python2.7/dist-packages/python_keystoneclient-0.6.0.2.g43f8870-py2.7.egg

b)
(.venv2)saju@rildemo2:/opt/horizon_reg_service$ sudo easy_install python-keystoneclient
Searching for python-keystoneclient
Best match: python-keystoneclient 0.6.0.2.g43f8870
Processing python_keystoneclient-0.6.0.2.g43f8870-py2.7.egg
python-keystoneclient 0.6.0.2.g43f8870 is already the active version in easy-install.pth
Installing keystone script to /usr/local/bin

Using /usr/local/lib/python2.7/dist-packages/python_keystoneclient-0.6.0.2.g43f8870-py2.7.egg
Processing dependencies for python-keystoneclient
Finished processing dependencies for python-keystoneclient
(.venv2)saju@rildemo2:/opt/horizon_reg_service$

Solutions
==========

1) (Tested and working)
sudo is probably screwing with $PATH. delete the virtualenv, `sudo -i` to get a root shell, then make the virtualenv without sudo (as root)
#sudo -i
#cd /opt
#virtualenv .venv
#source .venv/bin/activate
#pip install python-keystoneclient


2)
the better thing to do would be to make the /opt/.venv folder, change the ownership to your user, and then do the virtualenv stuff as your normal user (without sudo)