本文介绍了Pythonpath仍然被忽略,无法使用pip在本地安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的pythonpath环境变量被忽略了.我在ubuntu上使用python 2.6.我的.bashrc中包含以下内容:

export PTYHONPATH=/my/home/mylibs/lib/python2.6/site-packages/:$PYTHONPATH

然后我使用以下命令安装新版本的numpy:

python setup.py install --prefix=/my/home/mylibs/

,它将在本地正确安装.但是,当我尝试安装依赖于numpy新版本的其他软件包(也使用setup.py)时,他们找不到它,因为默认情况下,加载的numpy是/usr/llib中的一个,而不是/usr/llib中指定的一个.我的PYTHONPATH.我的PYTHONPATH设置正确,但是系统范围的目录仍在覆盖它.

如何解决?我只希望在执行import numpy时访问我的本地版本的numpy.我在python 2.4上看到了与此相关的其他文章,但据我所知,它从未得到解决.另外,我现在不想安装pip或virtualenv来执行此操作.似乎应该可以使用传递给setup.py--prefix--home选项,然后更改PYTHONPATH,但这对我来说不起作用...首先读取系统范围的lib目录. /p>

edit :我尝试遵循建议并使用pip.我在系统范围内安装了无法识别--user(版本0.3)的旧pip.我试图用pip本身升级pip,但是由于我无法在本地安装它而导致失败,因此pip install pip --upgrade --user不是一个选择.我下载了新版本的pip并本地安装在主目录中,但是在提示符下键入pip时,仍使用系统范围的旧版本.我查看了pip软件包并找到了runner.py,所以我尝试使用它来安装软件包,方法是:

runner.py install --user numpy --upgrade

这仍然失败,但权限被拒绝:

OSError: [Errno 13] Permission denied: '/usr/bin/f2py2.6'

--user似乎坏了.我也不确定这将如何解决系统范围的python使用/usr/lib中的系统范围的软件包的事实...对此有解决方案吗?如今似乎几乎不可能在python中安装本地软件包.

解决方案

好的,Python将使用找到的第一个包.在系统一号之后,PYTHONPATH被附加到sys.path中.因此,通常它将首先找到该系统.但是,正式的"每用户软件包目录似乎位于该目录之前.因此,创建您的个人site-packages目录:

mkdir -p $HOME/.local/lib64/python2.7/site-packages
mkdir $HOME/bin

(您可能必须将"lib64"更改为"lib32"或仅将"lib")

此目录在我的系统上放置在系统目录之前.但是您应该通过打印sys.path来进行验证.

然后将您的软件包安装到那里.但是,最新版本pip中的--user选项应该已经将其放置在那里.

作为列表度假村,您可以操纵sys.path.您可以将目录插入系统站点包之前的sys.path中,然后导入numpy.

您从脚本安装中遇到权限错误,尝试将其放置在系统位置.您可以传递其他选项以在$ HOME/bin目录中安装脚本.

像这样安装:

pip install --user --install-option="--install-scripts=$HOME/bin"

I'm finding that my pythonpath environment variable is ignored. I'm using python 2.6 on ubuntu. I have in my .bashrc the following:

export PTYHONPATH=/my/home/mylibs/lib/python2.6/site-packages/:$PYTHONPATH

Then I install a new version of numpy using:

python setup.py install --prefix=/my/home/mylibs/

and it gets correctly installed locally. However, when I try to install other packages (also using setup.py) that depend on the new version of numpy, they cannot find it, because by default the loaded numpy is the one in /usr/llib, and not the one specified in my PYTHONPATH. My PYTHONPATH gets correctly set but the system-wide directory is still overruling it.

How can this be fixed? I just want my local version of numpy to be accessed when I do import numpy. I saw other posts related to this with python 2.4 but as far as I can tell it never got resolved. Also, i'd like to do this without installing pip or virtualenv for now. It seems like it should be possible using --prefix or --home options passed to setup.py and then alteration of PYTHONPATH but this does not work for me... the system wide lib dirs are read first.

edit: I try to follow the suggestions and use pip. I have a system wide install of an old pip that does not recognize --user (ver 0.3). I tried to upgrade pip with pip itself but of course that failed because I cannot install it locally, so pip install pip --upgrade --user is not an option. I downloaded a new version of pip and installed locally in my home directory but the system wide old one is still used when I type pip at the prompt. I looked into the pip package and found runner.py so I tried to use it to install packages using:

runner.py install --user numpy --upgrade

That still fails with permission denied:

OSError: [Errno 13] Permission denied: '/usr/bin/f2py2.6'

It looks like --user is broken. I also am not sure how this would solve the fact that the system wide python uses the system wide packages in /usr/lib... is there a solution to this? It seems like it's virtually impossible to install local packages in python nowadays.

解决方案

Ok, Python will use the first package it finds. The PYTHONPATH gets appended to sys.path, after the system one. So it will normally find the system one first. But the "official" per-user packages directory seems to be placed before that. So create your personal site-packages directory:

mkdir -p $HOME/.local/lib64/python2.7/site-packages
mkdir $HOME/bin

(You may have to change "lib64" to "lib32" or just "lib")

This directory gets placed before the system one on my system. But you should verify it by printing out sys.path.

Then install your packages into there. However, the --user option in the latest pip version should already place it there.

As a list resort you can manipulate sys.path. You can insert your directory into sys.path before the system site-packages, then import numpy.

You are getting permissions errors from the scripts installation, trying to put that in the system location. You can pass additional options to install scripts in your $HOME/bin directory.

Install like this:

pip install --user --install-option="--install-scripts=$HOME/bin"

这篇关于Pythonpath仍然被忽略,无法使用pip在本地安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:47