[英]Upgrade version of scikit-learn included in Enthought Canopy distribution
I have EPD 7.3.1 installed (nowadays called Enthought Canopy), which comes with scikit-learn v 0.11. 我安装了EPD 7.3.1(现称为Enthought Canopy),它带有scikit-learn v 0.11。 I am running Ubuntu 12.04.
我正在运行Ubuntu 12.04。 I need to install v 0.12 of scikit-learn.
我需要安装v 0.12的scikit-learn。
The scikit-learn doc says clone the repository, add the scikit-learn directory to your PYTHONPATH, and build the extension in place: python setup.py build_ext --inplace
scikit-learn doc说克隆存储库,将scikit-learn目录添加到PYTHONPATH,然后构建扩展:
python setup.py build_ext --inplace
The problem is that EPD is its own closed world (with mulitple scikit dirs): 问题是EPD是它自己封闭的世界(有多个scikit dirs):
./lib/python2.7/site-packages/scikits/
./lib/python2.7/site-packages/sklearn
And then there's: 然后是:
./EGG-INFO/scikit_learn/
I really don't want to experiment as it has taken a very long time to get things tuned to this point. 我真的不想进行实验,因为花了很长时间才把事情调到这一点。 Should I follow scikit-learn's directions in this case?
在这种情况下,我应该遵循scikit-learn的指示吗?
The actions described on the scikit-learn website work irrespective of the scikit-learn version in EPD. scikit-learn网站上描述的行动与EPD中的scikit-learn版本无关。 Python will automatically use the scikit-learn version set in the
PYTHONPATH
environment variable , which you should set to the directory path of the Git version of scikit-learn. Python将自动使用
PYTHONPATH
环境变量中设置的scikit-learn版本,您应将其设置为scit-learn的Git版本的目录路径。
If you use Bash on a Unix-like system, you should do the following: 如果在类Unix系统上使用Bash,则应执行以下操作:
/home/yourname/bin/scikit-learn
) /home/yourname/bin/scikit-learn
) .bashrc
and add the line: export PYTHONPATH="/home/yourname/bin/scikit-learn";
.bashrc
并添加以下行: export PYTHONPATH="/home/yourname/bin/scikit-learn";
python
python
以交互模式启动Python
import sklearn
import sklearn
: import sklearn
sklearn.__verion__
this should now show '0.12-git'
instead of 0.11
sklearn.__verion__
现在应该显示'0.12-git'
而不是0.11
Why does this work? 为什么这样做? Python uses the variable
sys.path
(a list
of paths) internally to keeps track of all the directories where it should look for modules and packages. Python在内部使用变量
sys.path
(路径list
)来跟踪它应该查找模块和包的所有目录。 Once a module or package is requested, Python will sequentially go through this list until it has found a match. 一旦请求模块或包,Python将按顺序浏览此列表,直到找到匹配项。 So, eg, a module can be listed multiple times in
sys.path
, but only the version which appeared first in the list will be used. 因此,例如,可以在
sys.path
多次列出模块,但只使用列表中首先出现的版本。
Every Python installation will have its own default set of paths listed in sys.path
. 每个Python安装都将在
sys.path
列出自己的默认路径集。 One way of extending sys.path
is by listing paths in PYTHONPATH
. 扩展
sys.path
一种方法是列出PYTHONPATH
路径。 Once Python starts it will read this environment variable and add it to the start of the sys.path
list. 一旦Python启动,它将读取此环境变量并将其添加到
sys.path
列表的开头。 So if you add the path to another version of scikit-learn to your PYTHONPATH
then (EPD's) Python will find that version of scikit-learn first and use it instead of the version listed further on in sys.path
. 因此,如果您将路径添加到另一个版本的scikit-learn到
PYTHONPATH
然后(EPD),Python将首先找到该版本的scikit-learn并使用它而不是sys.path
进一步列出的版本。
To view sys.path
, simply import sys
and then print sys.path
. 要查看
sys.path
,只需import sys
然后print sys.path
。 Also, eg, if you only want to use the 0.12 version of scikit-learn in one Python program and use the 0.11 version as default in all other Python programs then you could leave the PYTHONPATH
empty and only insert the path to scikit-learn 0.12 manually at the top of your code: 另外,例如,如果您只想在一个Python程序中使用0.12版本的scikit-learn并在所有其他Python程序中使用0.11版本作为默认值,那么您可以将
PYTHONPATH
保留为空并且仅将路径插入scikit-learn 0.12手动在代码顶部:
import sys
sys.path.insert(0, '/home/yourname/bin/scikit-learn')
import sklearn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.