4

I am trying to install a python package using setup.py in virtualenv with Python 2.7. The requirement is package and it's dependencies should go inside site-package folder of virtualenv path.

So I activated virtualenv and went to location where setup.py is present. But when I run python setup.py install, the package and it's dependencies gets installed inside system python site-package.

In order to install it inside virtualenv I had to specify the location of python inside virtualenv like <virtualenv path>/bin/python setup.py install. This looks strange to me given the virtualenv is already activated. Is this the correct way of installation using setup.py inside virtualenv? If yes then why? If not what is the correct way of doing it?

Edit:

I ran which python and it pointed to location of python inside virtualenv.

I am using centos 6 machine.

Aleksandar Makragić
  • 1,957
  • 17
  • 32
Yogesh
  • 83
  • 2
  • 7
  • 3
    I suspect your virtualenv is not really activated, as the question does not have any command line samples to confirm this. You can always confirm by doing `echo $PATH` or `which python`. Also you can try `pip install .` instead of `python setup.py install`. – Mikko Ohtamaa Jan 19 '16 at 10:46
  • 1
    I have found that `which python`, `which pip`, etc. are a useful command to know which python is used and as a test of virtualenv activation. If a virtualenv is not activated `which python` yields `/usr/bin/python`. With the virtualenv activated it yields `/home/ubuntu/.virtualenvs/myvirtualenvironmentname/bin/python` and is a clue to which site-package is the destination for installed packages. – dmmfll Jan 19 '16 at 10:50
  • Hello Yogesh which OS you are using. Please let me know, it would help me fix your issue. – Chitrank Dixit Jan 19 '16 at 13:49

2 Answers2

0

Linked site-packages

Virtualenv may be linking its site-packages directory to the global site-packages. From the man page (mine is 1.5.2):

--no-site-packages    Don't give access to the global site-packages dir
                      to the virtual environment

At version 1.5.2, this linking is default and you need to specify otherwise when creating the environment. In future versions, this behavior was switched so that NOT linking is the default behavior.

What to do:

You can check whether it is linked by the existence of the <environment>/lib/python<ver>/no-global-site-packages.txt file. If this is not present, your site-packages are linked, meaning virtualenv would install to and use the global site-packages, as opposed to creating its own copy as you expected. Unfortunately, there isn't a way to change this after the fact. You will need to recreate the virtualenv using the --no-site-packages option this time.

Zach
  • 139
  • 2
  • 10
0

If you follow the py2.7 tutorial on setup.py, you will use

from distutils.core import setup

In my virtualenv (CENTOS 6.0 with --no-site-packages active), it creates the same problem.

Instead, if you use

from setuptools import setup

It works.

I do not know why. Hope someone else can point it out.

Junchen
  • 1,749
  • 2
  • 18
  • 25