简体   繁体   English

Ubuntu上的Django,Pyenv和Git文件结构

[英]Django, Pyenv and Git file structure on Ubuntu

在此处输入图片说明

I am working to set up a django project on ec2 with an Ubuntu 14.4 LTS instance. 我正在使用Ubuntu 14.4 LTS实例在ec2上建立django项目。 I want to write my code using python 3 and django. 我想使用python 3和django编写代码。 I've been advised that the best way to do this is to use a virtualenv. 我被告知,做到这一点的最佳方法是使用virtualenv。 Following https://robinwinslow.co.uk/2013/12/26/python-3-4-virtual-environment/ https://robinwinslow.co.uk/2013/12/26/python-3-4-virtual-environment/

I tried: 我试过了:

 ~$ pyvenv-3.4 djenv

Which appears to create a virtualenv (please see screenshot). 这似乎创建了一个virtualenv(请参见屏幕截图)。 Now I have 2 questions: 现在我有两个问题:

1) What folder should I place my django project. 1)我应该把我的django项目放在哪个文件夹中。 - I'm thinking within the djenv folder. -我在djenv文件夹中。 In other words I'd run: 换句话说,我会跑步:

/home/ubuntu/djenv$ django-admin.py startproject testproject.

2) init a git repository. 2)初始化git仓库。 I'm assuming I'd to it it in the same location, ie 我假设我会在同一位置使用它,即

/home/ubuntu/djenv$ git init

from within 从内部

Does this seem correct or is there a better way to do this? 这看起来是正确的还是有更好的方法来做到这一点?

Your project source code should be entirely separate from your virtual env in the file system. 您的项目源代码应与文件系统中的虚拟环境完全分开。 If they are in the same place, as you suggest, then you will end up checking libraries into your git repository needlessly and that will take up extra space end up causing problems. 如果您将它们放在同一位置(如您建议的那样),那么最终将不必要地将库检入git存储库,这将占用额外的空间,最终导致问题。

Once you have activated a virtualenv you can run Python and use all the libraries in it. 激活virtualenv后,您可以运行Python并使用其中的所有库。 You don't need any connection in the file system. 您不需要文件系统中的任何连接。

You should store a PIP file in your git repo somewhere that describes how to install the relevant dependencies into your virtualenv so you can re-create it on another machine. 您应该在git仓库中存储一个PIP文件,该文件描述了如何将相关的依赖项安装到virtualenv中,以便可以在另一台计算机上重新创建它。

On my machine my projects are in /home/me/projects/«project» and my virtualenvs are in /home/me/envs/«envname» . 在我的机器上,我的项目在/home/me/projects/«project»而我的virtualenvs在/home/me/envs/«envname» I use virtualenvwrapper which makes things easy. 我使用virtualenvwrapper ,这使事情变得容易。

Create an environment 创建环境

$ mkvirtualenv test
New python executable in test/bin/python
Installing Setuptools......done.
Installing Pip.........done.

Activate it 激活它

$ workon test

Python now refers to the one in my environment. Python现在是指我的环境中的那个。 It has its own site-packages etc. 它有自己的网站包装等。

$ which python
/Users/joe/Envs/test/bin/python

If we run it and look at the paths, they point to the virtualenv. 如果我们运行它并查看路径,它们将指向virtualenv。 This is where it looks for packages (lots removed from my path for simplicity). 在这里寻找软件包(为简便起见,从我的路径中删除了很多软件包)。

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/Users/joe/Envs/test/lib/python27.zip', '/Users/joe/Envs/test/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Users/joe/Envs/test/lib/python2.7/site-packages']
>>>

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

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