简体   繁体   English

如果从python2.6导入要与python2.7一起使用的站点包,可能会发生问题?

[英]Issues that could happen if importing site-packages from python2.6 to be used with python2.7?

I finally managed to install numpy, but it seems to only work in python2.6 . 我终于设法安装了numpy,但是它似乎只能在python2.6中工作。 I don't know how to install it in the 2.7 folder (been trying for hours, but I'm just a beginner developer in my first months). 我不知道如何将其安装在2.7文件夹中(已经尝试了几个小时,但是头几个月我只是一个初学者。) Anyway, if I use Python 2.7 and append the absolute path to sys.path, could there be problems? 无论如何,如果我使用Python 2.7并将绝对路径附加到sys.path,是否会出现问题?

Any suggestions? 有什么建议么?

Thank you. 谢谢。

It could partially work but this is a bad idea. 它可能会部分起作用,但这不是一个好主意。 Just don't do it. 只是不要这样做。 Even if it seems to work, it may not. 即使它看起来可行,也可能不起作用。 And if it really does, then it will fail randomly in the future. 如果确实如此,那么将来它将随机失败。

These are the potential problems that come into my mind: 这些是我想到的潜在问题:

  1. Extensions (those written in C, C++ etc.) are specific to a particular Python version; 扩展(用C,C ++等编写的扩展)特定于特定的Python版本。 and numpy has a few extensions, AFAICS. numpy有一些扩展名AFAICS。 It will work only if you don't use any of them (ie use pure Python modules); 仅当您不使用任何一个(即使用纯Python模块)时,它才有效。
  2. Python compiles modules into bytecode. Python将模块编译成字节码。 The bytecode is specific to a particular Python version. 字节码特定于特定的Python版本。 If you use modules from python2.6 directory in python2.7, the compiled files will collide. 如果您使用python2.7中python2.6目录中的模块,则编译后的文件将发生冲突。 I doubt this will cause major problems except for the fact that they will be recompiled every time Python version is switched; 我怀疑这会引起严重的问题,除了每次切换Python版本时都会重新编译它们。
  3. Python code can be version-specific. Python代码可以是特定于版本的。 It's unlikely for minor versions (but for example Python 2/3 could have serious differences) but still can happen. 对于次要版本,这不太可能(但例如Python 2/3可能会有严重差异),但仍然可能发生。 In other words, the modules installed for Python2.6 can be actually a bit different than those for Python2.7; 换句话说,为Python2.6安装的模块实际上可能与为Python2.7安装的模块有所不同。
  4. If you change the loading order, Python2.7 may start loading some standard modules from Python2.6. 如果更改加载顺序,Python2.7可能会开始从Python2.6加载一些标准模块。 it could work, it could cause random breakages; 它可能会起作用,可能会导致随机损坏;
  5. It will make all modules installed for Python2.6 visible. 它将使为Python2.6安装的所有模块均可见。 It can cause a few random switches somewhere with unpredictable result. 它可能导致某些地方的一些随机切换,结果无法预测。 I doubt there's something specific for that version but some modules may actually decide to use some kind of deprecated interface finding it visible. 我怀疑该版本是否有特定的功能,但某些模块实际上可能决定使用某种已弃用的接口以使其可见。

There could be more. 可能还有更多。 You may actually try but be prepared that you may waste a lot of time trying to find out why something does not work as expected later. 您实际上可以尝试,但是要做好准备,可能会浪费大量时间试图找出为什么某些东西以后无法按预期工作的原因。

And unless I'm missing something, I think installing numpy for Python2.7 involves mostly running the setup using Python 2.7; 而且,除非我缺少任何东西,否则我认为为python2.7安装numpy主要涉及使用 python 2.7运行安装程序。 like: 喜欢:

python2.7 setup.py clean
python2.7 setup.py build
python2.7 setup.py install

Depending on your particular install/system, it may be preferable to use the package manager, binary bundle or a tool like pip instead. 根据您的特定安装/系统,可能更可取的是使用软件包管理器,二进制捆绑软件或诸如pip类的工具。 If you'd like more details on how to enforce Python2.7 with those, you'd have to tell us which one is of your choice. 如果您想了解更多有关如何使用它们执行Python2.7的详细信息,则必须告诉我们您选择了哪个。

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

相关问题 如何将Python2.6站点包移动到Python2.7中? - How can I move my Python2.6 site-packages into Python2.7? 将 django 从 python2.6 更改为 python2.7 - change django from python2.6 to python2.7 没有VirtualEnv的Python2.7中的站点包 - Site-Packages in Python2.7 without VirtualEnv 如何手动将文件夹复制到/app/.heroku/python/lib/python2.7/site-packages/? - How to manually copy folder to /app/.heroku/python/lib/python2.7/site-packages/? 如何忽略〜/ .local / lib / python2.7 / site-packages中的python模块? - How to ignore python module in ~/.local/lib/python2.7/site-packages? ImportError:dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so - ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so 如何在Linux下的/usr/local/lib/python2.7/site-packages下安装Pip - how to Install Pip under /usr/local/lib/python2.7/site-packages in Linux “/lib/python2.7/site-packages/不支持.pth文件”在MacOS上安装pip - “/lib/python2.7/site-packages/ does NOT support .pth files” installing pip on MacOS 找不到:/lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv - Not found : /lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv 当我也有Python2.7(OS X)时,virtualenv仅创建/lib/Python2.6 - virtualenv only creates /lib/Python2.6 when I also have Python2.7 (OS X)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM