简体   繁体   中英

Fabric under Virtualenv: How to obtain the system's Python library path (not the library path of the virtualenv Python)

I'm starting using Fabric as simple deployment tool for a Python project, but there's a task that needs to know where's the system Python library path, to correctly setup some packages symlinks.

So the question is: How, in my fabfile, can I obtain the system Python path? For instance, this Python code return the correct library path:

# Without virtualenv activated
>>> from distutils.sysconfig import get_python_lib;
>>> print get_python_lib()
'/usr/lib/python2.7/dist-packages'

# With virtualenv activated
>>> from distutils.sysconfig import get_python_lib;
>>> print get_python_lib()
'/home/mandx/dev/my_project/env/lib/python2.7/site-packages'

In my case, I need to know both, when running a task in Fabric (and with virtualenv active).

I'll explain my need for this: I want to use WeasyPrint to generate PDFs by simply passing HTML and CSS content to a constructor and calling a render method. This flexibility is good because a can now leverage the PDF layout to a designer with CSS knowledge, and WeasyPrint strives CSS3 compatibility.

And the trade-off is that it depends on some libraries that can not be installed with Pip (specifically Pango, GdkPixbuf, and Cairo). So the solution I have for now is to have those installed system-wide and symlink them to the project's virtualenv.

I don't like much the idea of using the virtualenv's --system-site-packages option, but I would like to hear why it would be better than my idea of symlinking.

只需运行Fabric Shell脚本命令任务来询问操作系统的python:

/usr/bin/python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM