简体   繁体   English

在Windows和Linux上开发Web应用程序

[英]Developing a web-app on Windows and Linux

I'm developing a web-app and the work needs to be done from two computers, one is running Linux the other is running Windows. 我正在开发一个网络应用程序,工作需要从两台计算机完成,一台运行Linux,另一台运行Windows。

This app is developed with Pyramid framework on Python 2.6.7 (this is what the server runs, and I can't change it) 这个应用程序是在Python 2.6.7上使用Pyramid框架开发的(这是服务器运行的,我无法更改它)

Following the tutorials in Pyramid site, I've created a virtualenv on the Linux machine, and created a project - tested it and it seems to run without issues on the Linux machine. 按照Pyramid网站上的教程,我在Linux机器上创建了一个virtualenv ,并创建了一个项目 - 测试它,它似乎在Linux机器上运行没有问题。 Now in order to sync the work to Windows, I thought of using git (with a free private projcet from bitbucket). 现在为了将工作同步到Windows,我想到了使用git(带有来自bitbucket的免费私有项目)。 I created a git project and pushed it to bitbucket. 我创建了一个git项目并将其推送到bitbucket。 I used this .gitignore file template and I've also added this line (I believe that venv is OS specific, but I could be wrong): 我使用了这个.gitignore文件模板,我也添加了这一行(我相信venv是特定于操作系统的,但我可能错了):

venv

After I cloned the project to Windows, I don't have a virtualenv - How do I create a venv that would be compatible with the one that exists on the Linux machine (my Windows machine has Python 2.7 installed on it, no sqlalchemy, etc.)? 在我将项目克隆到Windows之后,我没有virtualenv - 如何创建一个与Linux机器上存在的venv兼容的venv(我的Windows机器上安装了Python 2.7,没有sqlalchemy等等) 。)? What is the 'correct' way of doing it? 这样做的“正确”方法是什么? Should I just give app (it was a spelling mistake, but I'll leave it for now) Windows and use Ubuntu on a virtualbox? 我应该给app(这是一个拼写错误, 我现在就把它留下)Windows并在虚拟机上使用Ubuntu?

EDIT: 编辑:

Although I have already accepted Rostyslav Dzinko's answer regarding the use of a requirements.txt file, the right way is to actually use the built in setup.py that is generated by pyramid's scaffold mechanism during the pcreate process. 虽然我已经接受了Rostyslav Dzinko关于使用requirements.txt文件的答案,但正确的方法是实际使用在pcreate过程中由金字塔的脚手架机制生成的内置setup.py So if anyone encounter this issue please consider trying: 因此,如果有人遇到此问题,请考虑尝试:

python setup.py develop

Virtualenv creates virtual environment for your Python interpreter. Virtualenv为您的Python解释器创建虚拟环境。 It means that each virtual environment can have different versions of same packages installed or different packages at all that are important only for your project (dependencies). 这意味着每个虚拟环境可以安装不同版本的相同软件包,或者根本只对您的项目(依赖项)重要的不同软件包。

If you want to manage dependencies, you can use pip to make your new virtual environment synchronized with old one. 如果要管理依赖项,可以使用pip使新虚拟环境与旧虚拟环境同步。

All you need to do is to create requirements.txt file and fill it with dependencies, eg: 您需要做的就是创建requirements.txt文件并用依赖项填充它,例如:

pyramid==1.0.1
...

Let this file be in your git repository. 让这个文件在你的git存储库中。

After cloning the source into newly created virtualenv on a new machine, you can install all dependencies with pip: 在新机器上将源克隆到新创建的virtualenv后,您可以使用pip安装所有依赖项:

pip install -r requirements.txt

A virtual-env is a Python runtime environment installed on your system. virtual-env是系统上安装的Python运行时环境。 It isn't part of your code-base and so shouldn't be in your Git repository. 它不是您的代码库的一部分,因此不应该在您的Git存储库中。

Install a virtual-env separately on each machine you use. 在您使用的每台计算机上单独安装virtual-env。

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

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