New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fabric.contrib.django does not use virtualenv django version #1033

Closed
anentropic opened this Issue Dec 4, 2013 · 7 comments

Comments

Projects
None yet
6 participants
@anentropic

anentropic commented Dec 4, 2013

I have activated my virtualenv and installed fabric via pip:

(myvenv)$ which fab
~/virtualenvs/myvenv/bin/fab

On my web host (WebFaction) there is a systemwide Django (1.3.3) and I have a newer version installed into the virtualenv for my project:

(myvenv)$ ipython
In [1]: import django

In [2]: django.get_version()
Out[2]: '1.4.10'

In my fabfile I added:

from fabric.contrib import django

django.settings_module('myapp.settings')
import django
print(django.get_version())
from django.conf import settings

I see the following:

(myvenv)$ fab
1.3.3
Traceback (most recent call last):
...
ValueError: Unable to configure filter 'require_debug_false': Cannot resolve 'django.utils.log.RequireDebugFalse': No module named RequireDebugFalse

So I'm getting an error due to fabric not using the virtualenv version of django

@anentropic

This comment has been minimized.

Show comment
Hide comment
@anentropic

anentropic Dec 4, 2013

Work-around... adding this to the top of the fabfile:

import sys
sys.path.insert(1, '/home/me/virtualenvs/myvenv/lib/python2.7/site-packages')

But I'm not sure exactly why I need to, shouldn't fab respect the virtualenv it was installed into?

anentropic commented Dec 4, 2013

Work-around... adding this to the top of the fabfile:

import sys
sys.path.insert(1, '/home/me/virtualenvs/myvenv/lib/python2.7/site-packages')

But I'm not sure exactly why I need to, shouldn't fab respect the virtualenv it was installed into?

@shuoli84

This comment has been minimized.

Show comment
Hide comment
@shuoli84

shuoli84 Feb 27, 2014

Similar issue here.
I load django by

django.project('project')

Then

def mock():
    from app.models import Model
    # Do some mocking stuff

def mock_machine():
    with virtualenv():
         run('fab mock')       

Even I added virtualenv() (It is a wrapper which sets path and prefix to virtual env), the run still failed with not able to load app.

shuoli84 commented Feb 27, 2014

Similar issue here.
I load django by

django.project('project')

Then

def mock():
    from app.models import Model
    # Do some mocking stuff

def mock_machine():
    with virtualenv():
         run('fab mock')       

Even I added virtualenv() (It is a wrapper which sets path and prefix to virtual env), the run still failed with not able to load app.

@moimael

This comment has been minimized.

Show comment
Hide comment
@moimael

moimael Jun 25, 2014

Any news on this ? I hit the same issue.

moimael commented Jun 25, 2014

Any news on this ? I hit the same issue.

@grucha

This comment has been minimized.

Show comment
Hide comment
@grucha

grucha Jul 22, 2014

Same here, installed fabric and fabtools into virtualenv it and I get

(someproject)TastypeAir:someproject | git:dev b28e8db 
$ fab dev xyz
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fabric/main.py", line 637, in main
    docstring, callables, default = load_fabfile(fabfile)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fabric/main.py", line 164, in load_fabfile
    imported = importer(os.path.splitext(fabfile)[0])
  File "/Users/sylwek/yp/someproject/fabfile.py", line 10, in <module>
    import fabtools
ImportError: No module named fabtools

It somehow uses my system (macports) fabric instead of virtualenv one, regardless of activated virtualenv:

$ which fab
/Users/sylwek/.virtualenvs/someproject/bin/fab

(I use fabric 1.9)

grucha commented Jul 22, 2014

Same here, installed fabric and fabtools into virtualenv it and I get

(someproject)TastypeAir:someproject | git:dev b28e8db 
$ fab dev xyz
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fabric/main.py", line 637, in main
    docstring, callables, default = load_fabfile(fabfile)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fabric/main.py", line 164, in load_fabfile
    imported = importer(os.path.splitext(fabfile)[0])
  File "/Users/sylwek/yp/someproject/fabfile.py", line 10, in <module>
    import fabtools
ImportError: No module named fabtools

It somehow uses my system (macports) fabric instead of virtualenv one, regardless of activated virtualenv:

$ which fab
/Users/sylwek/.virtualenvs/someproject/bin/fab

(I use fabric 1.9)

@kaaveland

This comment has been minimized.

Show comment
Hide comment
@kaaveland

kaaveland Dec 22, 2015

Bit hard to pintpoint this without some more information. I'd be very interested in knowing what happens if this file is launched like a normal python module eg python fabfile.py ? That way, it should not use fabrics custom module loading.

Fabric does do some changes to sys.path in loading, but I can't see it adding any paths other than the directory where the fabfile lives prior to trying to perform the import (and only if it is not already on sys.path).

Would it be possible to see what sys.path contains at the top of the fabfile?

kaaveland commented Dec 22, 2015

Bit hard to pintpoint this without some more information. I'd be very interested in knowing what happens if this file is launched like a normal python module eg python fabfile.py ? That way, it should not use fabrics custom module loading.

Fabric does do some changes to sys.path in loading, but I can't see it adding any paths other than the directory where the fabfile lives prior to trying to perform the import (and only if it is not already on sys.path).

Would it be possible to see what sys.path contains at the top of the fabfile?

@anentropic

This comment has been minimized.

Show comment
Hide comment
@anentropic

anentropic Dec 23, 2015

amazingly 2 years later I can still reproduce this :)

quite possibly the problem is some weird misconfiguration on my server, or an old version of virtualenv or something

I'm hosting on WebFaction. This is what my sys.path looks like if I print it before modifying at the top of the fabfile:

['/home/anentropic/webapps/django__1_4/myproj',
 '/home/anentropic/virtualenvs/myproj/bin',
 '/home/anentropic/lib/python2.7/setuptools-0.6c11-py2.7.egg',
 '/home/anentropic/lib/python2.7/pip-1.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/sorl_thumbnail-11.05.1-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_denorm-0.2.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/distribute-0.6.10-py2.7.egg',
 '/home/anentropic/lib/python2.7/URLObject-0.5-py2.7.egg',
 '/home/anentropic/lib/python2.7/simplejson-2.1.5-py2.7-linux-i686.egg',
 '/home/anentropic/lib/python2.7/bunch-1.0.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_notification-0.2a1.dev4-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_storages-1.2a-py2.7.egg',
 '/home/anentropic/lib/python2.7/satchless-2011.9.pre-py2.7.egg',
 '/home/anentropic/lib/python2.7',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
 '/home/anentropic/virtualenvs/myproj/src/ebaysync',
 '/home/anentropic/virtualenvs/myproj/lib/python27.zip',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/plat-linux2',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-tk',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-old',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages',
 '/home/anentropic/webapps/django__1_4/lib/python2.7'
]

so the problem is that the virtualenv site-packages is almost at the bottom of the list, behind a bunch of stuff from the system user python2.7

if I run python fabfile.py I have exactly the same problem

now, I am stuck using old virtualenv==1.10.0 since anything newer clashes with the old setuptools==0.6c11 ...and this is in the system root python (which on webfaction is shared with other users) and I can't upgrade it

related: #1207 (comment)

anyway it doesn't happen locally so I think problem is related to the messed up situation on my webfaction host

anentropic commented Dec 23, 2015

amazingly 2 years later I can still reproduce this :)

quite possibly the problem is some weird misconfiguration on my server, or an old version of virtualenv or something

I'm hosting on WebFaction. This is what my sys.path looks like if I print it before modifying at the top of the fabfile:

['/home/anentropic/webapps/django__1_4/myproj',
 '/home/anentropic/virtualenvs/myproj/bin',
 '/home/anentropic/lib/python2.7/setuptools-0.6c11-py2.7.egg',
 '/home/anentropic/lib/python2.7/pip-1.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/sorl_thumbnail-11.05.1-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_denorm-0.2.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/distribute-0.6.10-py2.7.egg',
 '/home/anentropic/lib/python2.7/URLObject-0.5-py2.7.egg',
 '/home/anentropic/lib/python2.7/simplejson-2.1.5-py2.7-linux-i686.egg',
 '/home/anentropic/lib/python2.7/bunch-1.0.0-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_notification-0.2a1.dev4-py2.7.egg',
 '/home/anentropic/lib/python2.7/django_storages-1.2a-py2.7.egg',
 '/home/anentropic/lib/python2.7/satchless-2011.9.pre-py2.7.egg',
 '/home/anentropic/lib/python2.7',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
 '/home/anentropic/virtualenvs/myproj/src/ebaysync',
 '/home/anentropic/virtualenvs/myproj/lib/python27.zip',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/plat-linux2',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-tk',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-old',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/home/anentropic/virtualenvs/myproj/lib/python2.7/site-packages',
 '/home/anentropic/webapps/django__1_4/lib/python2.7'
]

so the problem is that the virtualenv site-packages is almost at the bottom of the list, behind a bunch of stuff from the system user python2.7

if I run python fabfile.py I have exactly the same problem

now, I am stuck using old virtualenv==1.10.0 since anything newer clashes with the old setuptools==0.6c11 ...and this is in the system root python (which on webfaction is shared with other users) and I can't upgrade it

related: #1207 (comment)

anyway it doesn't happen locally so I think problem is related to the messed up situation on my webfaction host

@kaaveland

This comment has been minimized.

Show comment
Hide comment
@kaaveland

kaaveland Dec 23, 2015

Okay, I'm not sure that issue is fixable from within fabric.

If wonder if maybe you're able to run pip install --upgrade virtualenv setuptools in your virtualenv and make a new one from that (don't know if this is supported) ?

kaaveland commented Dec 23, 2015

Okay, I'm not sure that issue is fixable from within fabric.

If wonder if maybe you're able to run pip install --upgrade virtualenv setuptools in your virtualenv and make a new one from that (don't know if this is supported) ?

@bitprophet bitprophet closed this Dec 31, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment