简体   繁体   English

Pip无法升级ubuntu 15.04中的内置包

[英]Pip can't upgrade a built-in package in ubuntu 15.04

I no longer seem to be able to upgrade a package already installed in Ubuntu 15.04. 我似乎无法升级已安装在Ubuntu 15.04中的软件包。 Pip still works, installing the package into /usr/local/python2.7/dist-packages , but the path lists /usr/python2.7/dist-packages at the top, and even PYTHONPATH can't get something above that line. Pip仍然可以正常工作,将软件包安装到/usr/local/python2.7/dist-packages ,但路径列表顶部是/usr/python2.7/dist-packages ,甚至PYTHONPATH也无法获得高于该行的内容。 I believe this works in older Ubuntus. 我相信这适用于较旧的Ubuntus。 I've been trying to find something in /usr/python/site.py , but it seems to do the right thing. 我一直试图在/usr/python/site.py找到一些东西,但它似乎做对了。 Adding -S does seem to stop the non-local version from being at the top. 添加-S似乎确实阻止非本地版本位于顶部。 I've seen this on two computers, I believe. 我相信,我在两台电脑上看过这个。

Some examples of the need for this: Updating to get a required feature/bugfix (for PILLOW, in my case) without APT uninstalling a bunch of packages that list that package as a requirement. 需要的一些例子:更新以获得所需的功能/错误修复(对于PILLOW,在我的情况下),没有APT卸载一堆列出该包作为要求的包。

Edit: For clarification, the question is: I want to reorder the directory search order to recover Ubuntu 14.10 behavior. 编辑:为了澄清,问题是:我想重新排序目录搜索顺序以恢复Ubuntu 14.10行为。 There are better ways to do this on many systems, but I want to use the built in apt packaging, just with one or two (potential) newer packages, like IPython and the like, rather than use virtual-env and Anacoda (both of which I use on other systems). 在许多系统上有更好的方法可以做到这一点,但是我想使用内置的apt包,只需要一个或两个(潜在的)新包,比如IPython等,而不是使用virtual-env和Anacoda(两者都是我在其他系统上使用)。 It looks like my desired behavior is the documented Debian behavior, so I'm not sure why it's reordering the path. 看起来我想要的行为是记录的Debian行为,所以我不确定它为什么重新排序路径。

Here's the path to demonstrate the problem, notice the PYTHONPATH variable is in the middle, with two git folders: 这是演示问题的路径,请注意PYTHONPATH变量位于中间,有两个git文件夹:

>>> sys.path
['',
'/usr/lib/python2.7/dist-packages', 
'/usr/local/lib/python2.7/dist-packages/requests-2.6.0-py2.7.egg', 
'/usr/local/lib/python2.7/dist-packages/octave_kernel-0.10.0-py2.7.egg',
'/home/username/git/maya',
'/home/username/git/udaq/pyUDAQ',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages/PILcompat', 
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7', 
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']

For reference, I have a matching system running 14.04, and it has exactly the expected behavior. 作为参考,我有一个运行14.04的匹配系统,它具有完全预期的行为。 The two PYTHONPATH dirs come first, then then later on the local dist-packages are above the built in. 两个PYTHONPATH dirs首先出现,然后是当地的dist-packages在内置之上。

There is a -t switch in pip. pip中有一个-t开关 It allows you to configure a directory where pip installs packages. 它允许您配置pip安装包的目录。

You can set the directory in a config file and forget about specifying it each time you install or upgrade packages 您可以在配置文件中设置目录,并在每次安装或升级软件包时忘记指定它

But generally it is a bad idea to upgrade packages installed by apt 但通常升级apt安装的软件包是个坏主意

Use virtualenv : 使用virtualenv

install virtualenv 安装virtualenv

$ sudo apt-get install python-virtualenv

create environment in MYENV directory 在MYENV目录中创建环境

$ virtualenv MYENV

activate environment in current shell (your app will need this as well on it's startup script) 激活当前shell中的环境(您的应用程序在其启动脚本上也需要它)

$ . MYENV/bin/activate

use pip/python from your venv located in MYENV directory (you own) 使用位于MYENV目录中的venv的pip / python(你自己)

(MYENV)$ pip ...  

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

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