简体   繁体   English

Python:移至新电脑

[英]Python: moving to a new computer

I'm moving from a computer with windows xp to one with windows 7 (64 bit) and I want to install Python on the new machine. 我正从一台装有Windows XP的计算机迁移到一台装有Windows 7(64位)的计算机,我想在新计算机上安装Python。 I'm currently using python 2.7 and 3.2 and a bunch of packages 我目前正在使用python 2.7和3.2和一堆软件包

1) Should I install the 64 bit versions? 1)我应该安装64位版本吗?

2) How can I tell which packages I currently have, so that I can get those for the new machine? 2)如何知道当前拥有哪些软件包,以便可以在新机器上获得它们?

If these are duplicates (my search skills seem to be failing), please point me to the threads where they're discussed. 如果这些是重复的(我的搜索技能似乎失败了),请指向我讨论它们的主题。

Type help('modules') of the Python shell to get a list of all installed modules. 键入Python shell的help('modules')以获取所有已安装模块的列表。 If you can find stable 64-bit versions, then by all means select 64-bit builds for installations. 如果可以找到稳定的64位版本,则一定要选择64位版本进行安装。

You can use pip now for this purpose. 您现在可以为此使用pip。

using pip list will give you a list of the packages that you have installed and the versions. 使用pip list将为您提供已安装的软件包和版本的列表。

You could also use pip freeze and then copy the output of this to a file and then use this as a requirements files so you can install those exact modules and versions again on the new computer. 您还可以使用pip freeze ,然后将其输出复制到文件中,然后将其用作需求文件,以便可以在新计算机上再次安装这些确切的模块和版本。 More information on pip is here is here 有关点子的更多信息在这里

but to install from a requirements files you would use 但要从需求文件安装,您将使用

pip install -r requirements.txt

From your Python home folder go to ../Lib/site-packages/ and save the folder listing to a file, eg ls > ~/my-python-modules.txt on Linux/OSX, or dir > my-python-modules.txt on Windows. 从您的Python主文件夹转到../Lib/site-packages/并将文件夹列表保存到文件,例如Linux / OSX上的ls > ~/my-python-modules.txtdir > my-python-modules.txt Windows上的dir > my-python-modules.txt The file will contain all the additional modules that have been installed on your system. 该文件将包含系统上已安装的所有其他模块。 Also, from the same folder search for *.pth files: they might contain the names of modules that were installed as Python Eggs. 另外,在同一文件夹中搜索*.pth文件:它们可能包含作为Python Eggs安装的模块的名称。

On Linux/OSX the location of the site-packages folder might vary: use locate -b site-packages to quickly find out where they are. 在Linux / OSX上, site-packages文件夹的位置可能有所不同:使用locate -b site-packages可以快速找出它们的位置。

To reinstall the modules it is best to use your system's built-in package manager if it has one (this will be the case if you use Linux or MacPorts), otherwise you will need to use easy_install (the package is called setuptools ) or pip ( url ). 要重新安装模块,最好使用系统的内置软件包管理器(如果有的话)(如果使用Linux或MacPorts,则为这种情况),否则,将需要使用easy_install (软件包称为setuptools )或pip网址 )。 On Windows with modules that need C/C++ compilation it is easiest to use binary executable installers, unless you have a sane build environment like MS Visual Studio or MinGW. 在带有需要C / C ++编译的模块的Windows上,除非您拥有健全的构建环境(如MS Visual Studio或MinGW),否则使用二进制可执行安装程序是最容易的。 If you install binary packages then it is probably best to get the 64-bit version to match your architecture. 如果安装二进制软件包,则最好获取64位版本以与您的体系结构匹配。 Not sure if 32 bit versions will work or will event install. 不知道32位版本是否可以工作或将进行事件安装。

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

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