如何“强制" python使用模块的特定版本? [英] How do I 'force' python to use a specific version of a module?

查看:117
本文介绍了如何“强制" python使用模块的特定版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,如果在其他地方用我没有想到的标签回答了这个问题,我深表歉意.

I'm new to python so I apologize if this has been answered elsewhere with tags I haven't thought of.

我正在尝试将numpy从现在的1.6版本更新到1.8版本.当我调用numpy时,我已经在python网站程序包中安装了numpy,它调用了旧的1.6版本.我尝试过寻找numpy 1.6的根目录,因此我可以将其删除,但这会导致:-

I'm trying to update numpy from the 1.6 version I have now to 1.8. I've installed numpy in my python site-packages when I call numpy it calls the old 1.6 version. I've tried looking for the root to numpy 1.6 so I can remove it but that leads to :-

import numpy
print numpy.__version__
print numpy.__file__
>>>
1.6.2
V:\Brian.140\Python.2.7.3\lib\site-packages\numpy\__init__.pyc

我使用以下命令将包含模块的文件夹添加到系统路径:-

I've added the folder containing the module to the system path using:-

sys.path.append('C:/Python27/Lib/site-packages')

,我知道这是可行的,因为我可以毫无错误地调用此位置中的其他模块,例如:-

and I know this works as I can call other modules in this location with no errors, for example:-

import wx
import Bio

import nose

不产生任何错误.为什么会发生这种情况,如何告诉python使用哪个版本的numpy?

produce no errors. Why is this happening and how can I tell python which version of numpy to use?

推荐答案

这是一个非常混乱的解决方案,可能不应该受到鼓励,但是我发现,如果我从系统路径中删除了numpy的旧版本,可以调用我想要的版本.具体的行是:-

This is a very messy solution and probably shouldn't be encouraged but I found that if I remove the location of the old version of numpy from the system path I can call the version I want. The specific lines were:-

import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.remove('V:\\\Brian.140\\\Python.2.7.3\\\Lib\\\site-packages')
import numpy

这篇关于如何“强制" python使用模块的特定版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆