Python: moving to a new computer

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:07:13

Type help('modules') of the Python shell to get a list of all installed modules. If you can find stable 64-bit versions, then by all means select 64-bit builds for installations.

ccpizza

From your Python home folder go to ../Lib/site-packages/ and save the folder listing to a file, e.g. ls > ~/my-python-modules.txt on Linux/OSX, or dir > my-python-modules.txt on Windows. 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.

On Linux/OSX the location of the site-packages folder might vary: use locate -b site-packages to quickly find out where they are.

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). 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. If you install binary packages then it is probably best to get the 64-bit version to match your architecture. Not sure if 32 bit versions will work or will event install.

You can use pip now for this purpose.

using pip list will give you a list of the packages that you have installed and the versions.

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. More information on pip is here is here

but to install from a requirements files you would use

pip install -r requirements.txt
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!