简体   繁体   English

处理python virtualenv中的几个软件包版本

[英]Deal with several package versions in python virtualenv

I'm using a computation server where I have no root privileges, so in order to be able to install whatever libraries I want, I created a virtualenv with --system-site-packages for python 2.6. 我正在使用没有root特权的计算服务器,因此为了能够安装所需的任何库,我为python 2.6创建了带有--system-site-packagesvirtualenv

Then, inside the virtual environment, I installed numpy version 1.8.2 because the system numpy version (1.3.0) is too old for my requirements: 然后,在虚拟环境中,我安装了numpy版本1.8.2,因为系统numpy版本(1.3.0)对于我的要求而言太旧了:

numpy - 1.3.0 - active development (/usr/lib64/python2.6/site-packages) numpy-1.3.0-主动开发(/usr/lib64/python2.6/site-packages)

numpy - 1.8.2 - non-active numpy-1.8.2-无效

I need the --system-site-packages option because I'm using some system libraries that I cannot install in the virtual environment. 我需要--system-site-packages选项,因为我正在使用某些无法在虚拟环境中安装的系统库。 However I am not able to tell the virtual environment to use the most recent version of numpy. 但是,我无法告诉虚拟环境使用numpy的最新版本。

Does anyone know how to select version 1.8.2 in the virtual environment? 有谁知道如何在虚拟环境中选择版本1.8.2? I tried with pkg_resources.require('numpy==1.8.2') but I got the error: 我尝试使用pkg_resources.require('numpy==1.8.2')但出现错误:

pkg_resources.VersionConflict: (numpy 1.3.0 (/usr/lib64/python2.6/site-packages), Requirement.parse('numpy==1.8.2'))

Is there some way of telling the virtual environment to look for libraries in the virtual virt2/lib64/python2.6/site-packages folder before looking in the system's /usr/lib64/python2.6/site-packages folder? 在查看系统的/usr/lib64/python2.6/site-packages文件夹之前,是否可以通过某种方法告诉虚拟环境在虚拟virt2/lib64/python2.6/site-packages文件夹中查找库?

It is likely that ou have been bitten by issue #461 and currently(as of August-2014) you CANNOT upgrade any system-inherited package because virtualenv 's paths are ordered AFTER any system-paths within sys.path . 您可能已被问题461咬伤,并且当前(截至2014年8月)您不能升级任何系统继承的程序包,因为virtualenv的路径是在sys.path任何系统路径之后排序的。

Your workaround it to move the (usually) last sys-path entry one position above: 您的解决方法是将(通常)最后一个sys-path条目移至上方一个位置:

  • Re-ordering sys.path with python-code., For instance, assuming that the index of your virtualenv's site-packages is the last one, you have to make sure that the following code runs before any other code: 例如,假设您的virtualenv site-packages的索引是最后一个,则用python代码重新排序sys.path ,您必须确保以下代码在任何其他代码之前运行:

     import sys; sys.path.insert(0, sys.path.pop(-1)) 
  • modify similarly your PYTHONPATH environment-variable before executing python-interpreter (see question #10738919 and ). 在执行python解释器之前,类似地修改您的PYTHONPATH环境变量(请参阅问题#10738919和)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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