将项目从一台计算机移动到另一台计算机 [英] Moving project from one computer to another
问题描述
我在一个PC上有一个用python 2.7构建的项目。它使用djagno 1.4.5和站点软件包中保留的其他一些模块。我试图将Lib\site-packages的内容复制到新的PC Python安装中,但是当我尝试运行manage.py runserver时却出现模块错误。我是否必须在新PC上重新安装所有内容,然后才传输项目文件?
I have a project I built in python 2.7 on one PC. It uses djagno 1.4.5 and some other modules that are kept in site-packages. I tried to copy the contents of Lib\site-packages to the new PC Python install, but I get missing module errors when I try to run manage.py runserver. Do I have to install everything again on the new pc and just transfer the project files?
推荐答案
通常,您会保留以下列表: requirements.txt
,并将文件保留在项目的根目录下。示例 requirements.txt
内容:
Usually, you keep a list of your project requirements in requirements.txt
and keep the file at the root of your project. Example requirements.txt
content:
Django==1.6.5
lxml==3.3
在新计算机上,克隆包含项目源代码的存储库(或以其他方式获得),然后通过 pip $ c $安装要求c>
python软件包管理器:
On the new computer, you clone the repository containing the project source code (or get it different way), then install the requirements via pip
python package manager:
pip install -r requirements.txt
此外,还有单独的虚拟环境对于每个项目基本上都是必须的。
Also, having separate virtual environments for every project is basically must have.
为了创建在当前python环境(虚拟或系统范围内)的需求列表中,运行:
In order to create the list of requirements from your current python environment (virtual or system-wide), run:
pip freeze > requirements.txt
这篇关于将项目从一台计算机移动到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!