在 virtualenv 中使用全局站点包中的一些模块 [英] make some modules from global site-packages available in virtualenv
问题描述
我想使用 virtualenv 的默认值(无站点包).
I want to use the default (no site packages) of virtualenv.
但是有些模块很难安装在 virtualenv 中(例如 gtk).困难"是指你需要安装很多 c 头文件,并且需要编译很多东西.
But some modules are difficult to install in a virtualenv (for example gtk). With "difficult" I mean that you need to have a lot of c-header files installed and a lot of stuff needs to be compiled.
我知道我可以通过不使用 pip 安装这些包来解决这个问题,而是创建符号链接以使某些模块从全局站点包目录中可用.
I know that I can solve this by not installing these packages with pip, but to create symlinks to make some modules available from the global site-packages directory.
但这是正确的方向吗?
有没有办法用 pip 或 virtualenv 创建符号链接?
Is there a way to create the symlinks with pip or virtualenv?
在 2013 年,我想要一些模块,如 psycopg2、gtk、python-ldap 和其他模块,它们通过 virtualenv 中的 rpm/dpkg 安装在我的 linux 服务器上.
In 2013 I wanted some modules like psycopg2, gtk, python-ldap and other which are installed on my linux server via rpm/dpkg in the virtualenv.
符号链接或其他变通办法确实让事情变得更复杂,而不是更简单.我们今天(2017 年)使用这个选项
The symlinking or other work-arounds did make things more complicated, not simpler. We use this option today (2017)
--system-site-packages
--system-site-packages
授予虚拟环境访问全局的权限网站包.
Give the virtual environment access to the global site-packages.
推荐答案
您如何从头开始编译这些硬"包?你在做什么:
How are you compiling each of these 'hard' packages from scratch? Are you doing something like:
python setup.py install
如果是这样,请将其替换为:
If so, replace that with:
python setup.py bdist_wheel
然后在 ./dist
目录中查找 .whl
文件.然后取出那个文件,然后执行(激活环境后)
Then look in the ./dist
directory for a .whl
file. Then take whatever that file is, and do (after activating the environment)
pip install `./dist/whateverTheFileIsCalled.whl`
这篇关于在 virtualenv 中使用全局站点包中的一些模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!