2012-04-14 71 views
0

安裝下載的程序包,我下載了一個倉庫Django class fixtures,我想與Python安裝的setup.py在我的virtualenv安裝:不能在virtualenv中

(test)/tmp/django-class-fixtures $ which python 
/home/kuba/.virtualenvs/test/bin/python 
(test)/tmp/django-class-fixtures $ python setup.py install 
... 
Extracting django_class_fixtures-0.8-py2.7.egg to /home/kuba/.virtualenvs/test/lib/python2.7/site-packages 
Adding django-class-fixtures 0.8 to easy-install.pth file 

Installed /home/kuba/.virtualenvs/test/lib/python2.7/site-packages/django_class_fixtures-0.8-py2.7.egg 
Processing dependencies for django-class-fixtures==0.8 
Finished processing dependencies for django-class-fixtures==0.8 
(test)/tmp/django-class-fixtures $ 

但理智最多,除了安裝蛋:

(test)/tmp/django-class-fixtures $ cdvirtualenv 
(test)/home/kuba/.virtualenvs/test $ cd lib/python2.7/site-packages 
(test)/home/kuba/.virtualenvs/test/lib/python2.7/site-packages $ ls 
django        PIL 
Django-1.4-py2.7.egg-info   PIL.pth 
django_class_fixtures-0.8-py2.7.egg pip-1.1-py2.7.egg 
easy-install.pth      setuptools-0.6c11-py2.7.egg 
IPython        setuptools.pth 
ipython-0.12-py2.7.egg-info 
(test)/home/kuba/.virtualenvs/test/lib/python2.7/site-packages $ 

你有什麼想法是怎麼回事?

編輯: 我想從外殼導入class_fixtures例如:

(test)/home/kuba/.virtualenvs/test/lib/python2.7/site-packages $ ipython 
Python 2.7.2+ (default, Oct 4 2011, 20:06:09) 
Type "copyright", "credits" or "license" for more information. 

IPython 0.11 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: import class_fixtures 
--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
/home/kuba/.virtualenvs/test/lib/python2.7/site-packages/<ipython-input-1-6a049da89661> in <module>() 
----> 1 import class_fixtures 

ImportError: No module named class_fixtures 

In [2]: 
+0

你有什麼期待嗎? – mensi 2012-04-14 12:40:27

+0

我希望我可以在shell中導入class_fixtures - 我已更新問題 – mrbox 2012-04-14 12:45:41

+0

該模塊被稱爲'django_class_fixtures' – mensi 2012-04-14 12:47:43

回答

3

的問題不在於沒有正在安裝的軟件包,它是IPython中忽略你的virtualenv的軟件包,如記錄here。我想你會發現只用python引發一個交互式shell就可以讓你導入一切正常。

爲了讓IPython的識別網站的包,把這樣的事情在一個名爲~/.ipython/profile_default/startup/00-virtualenv.py或類似的文件:

from __future__ import print_function 
import site 
from os import environ 
from os.path import join 
from sys import version_info 

if 'VIRTUAL_ENV' in environ: 
    virtual_env = join(
     environ.get('VIRTUAL_ENV'), 
     'lib', 
     'python%d.%d' % version_info[:2], 
     'site-packages' 
    ) 
    site.addsitedir(virtual_env) 
    print('VIRTUAL_ENV ->', virtual_env) 
    del virtual_env 
    del site, environ, join, version_info