建议先设置虚拟环境模式
easy_install virtualenv
root@as3:~# virtualenv dev
显示:
New python executable in dev/bin/python
Installing Setuptools.......................................................................................
.................................................................................................
......................................done.
Installing Pip..............................................................................................
.................................................................................................
.................................................................................................
.....................................done.
root@as3:~# dev/bin/python -V
Python 2.7.6
root@as3:~# cd dev
root@as3:~/dev# ls
bin include lib
root@as3:~/dev# ls bin
activate activate.fish easy_install pip python python2.7
activate.csh activate_this.py easy_install-2.7 pip-2.7 python2
root@as3:~/dev# source bin/activate (激活dev这个环境,这会让dev虚拟环境下的site-packages成为默认的版本)
(dev)root@as3:~/dev# (运行source /root/dev/bin/activate激活虚拟环境后,提示符就由“root@as3:~/dev#”变成了
“(dev)root@as3:~/dev#”,说明现在进入了虚拟环境模式!至此,虚拟环境模式设置成功)
(dev)root@as3:~/dev# pip install hyde
会显示:
...
Successfully installed hyde fswrap commando PyYAML Markdown MarkupSafe Pygments typogrify smartypants Jinja2
Cleaning up...
(dev)root@as3:~/dev# hyde --version
hyde 0.8.8 (这次运行hyde --version终于不再出错,而且显示的hyde版本为0.8.8)
(dev)root@as3:~/dev# hyde -s hyde-site create (在当前目录下,会生成hyde-site目录)
显示:
04:14:29 hyde Creating site at [/root/dev/hyde-site] with layout [/root/dev/lib/python2.7/site-packages/hyde/layouts/basic]
04:14:29 hyde Site creation complete
(dev)root@as3:~/dev#
(dev)root@as3:~/dev# ls
bin hyde-site include lib
(dev)root@as3:~/dev# cd hyde-site
(dev)root@as3:~/dev/hyde-site# ls
content info.yaml layout README.markdown site.yaml
(dev)root@as3:~/dev/hyde-site# hyde gen (这个就是生成/更新静态网站的命令)
(dev)root@as3:~/dev/hyde-site# ls
content deploy info.yaml layout README.markdown site.yaml (新出现了deploy目录)
(dev)root@as3:~/dev/hyde-site# cd deploy
(dev)root@as3:~/dev/hyde-site/deploy# ls
about.html blog index.html portfolio
apple-touch-icon.png favicon.ico media
(dev)root@as3:~/dev/hyde-site/deploy#
(可见~/dev/hyde-site/deploy/就是静态网站的根目录)
(dev)root@as3:~/dev/hyde-site/deploy# nohup Rwebserver 45367 > /dev/null &
(访问http://as3.brite.biz:45367/,立马可看到网站效果)
发贴方法:
(dev)root@as3:~/dev/hyde-site/deploy# cd ..
(dev)root@as3:~/dev/hyde-site# ls
content deploy info.yaml layout README.markdown site.yaml
(dev)root@as3:~/dev/hyde-site# cd content
(dev)root@as3:~/dev/hyde-site/content# ls
about.html blog index.html portfolio
apple-touch-icon.png favicon.ico media
(dev)root@as3:~/dev/hyde-site/content# cd blog
(dev)root@as3:~/dev/hyde-site/content/blog# ls
angry-post.html excerpts.xml index.html sad-post.html
atom.xml happy-post.html meta.yaml tags
(dev)root@as3:~/dev/hyde-site/content/blog#
按happy-post.html的内容,新建帖子test1.html,格式如下:
---
title: test1
created: !!timestamp '2013-12-02 10:00:00'
tags:
- misc1
- misc2
---
{% mark excerpt -%}
这里写摘要。
{%- endmark %}
这里写摘要之后的正文。
然后:
(dev)root@as3:~/dev/hyde-site/content/blog# cd ~/dev/hyde-site
(dev)root@as3:~/dev/hyde-site# hyde gen
不过我发表成功的帖子http://hyde-new.brite.biz/blog/test1.html并未显示在
http://hyde-new.brite.biz/blog/页面,有点奇怪。-此问题已解决,办法:
(dev)root@as3:~/dev/hyde-site/content/blog# cd ~/dev/hyde-site
(dev)root@as3:~/dev/hyde-site# hyde gen -r (这里r是regenerate的意思)
注意:如果你之前安装过旧版的hyde-https://github.com/lakshmivyas/hyde,而你又不在virtualenv下安装新版的hyde,那么在你安装新版的hyde,并运行命令hyde -h后,你会遇到出错提示:
pkg_resources.VersionConflict: (hyde 0.8.8 (/usr/local/lib/python2.7/site-packages/hyde-0.8.8-py2.7.egg), Requirement.parse('hyde==0.5.3'))
解决办法就是进入virtualenv,安装新版的hyde,这样即可避免与旧版的hyde发生冲突。
旧版hyde的安装,请见http://briteming.blogspot.co.uk/2013/11/linux-vpspythonhyde.html
演示站点:http://hyde-new.brite.biz/index.html
http://hyde-new.brite.biz/blog/
http://hyde-new.brite.biz/blog/test1.html
http://hyde-new.brite.biz/blog/test2.html
http://hyde-new.brite.biz/blog/fengyuwuzu.html
http://hyde-new.brite.biz/blog/chinese-economy.html
项目地址:https://github.com/hyde/hyde/
https://github.com/hyde/hyde/issues/4 ----------------------------------
virtualenvwrapper
or:
Depending on your MSYS setup, you may need to install the MSYS mktemp
binary in the MSYS_HOME/bin folder.
or:
An alternative to installing it into the global site-packages is to
add it to your user local directory
(usually ~/.local).
After editing it, reload the startup file (e.g., run source
~/.bashrc).
To override the $PATH search, set the variable
VIRTUALENVWRAPPER_PYTHON to the full path of the interpreter to
use and VIRTUALENVWRAPPER_VIRTUALENV to the full path of the
virtualenv binary to use. Both variables must be set before
sourcing virtualenvwrapper.sh. For example:
Editing the skeleton files for new accounts means that each new user will have their private startup files preconfigured to load virtualenvwrapper. They can disable it by commenting out or removing those lines. Refer to the documentation for the shell and operating system to identify the appropriate file to edit.
Modifying the global startup file for a given shell means that all users of that shell will have virtualenvwrapper enabled, and they cannot disable it. Refer to the documentation for the shell to identify the appropriate file to edit.
from http://virtualenvwrapper.readthedocs.org/en/latest/install.html
----------------------------------------
http://www.virtualenv.org/en/latest/
https://github.com/pypa/virtualenv
----------------------------------------------
1。安装
easy_install virtualenv
2。创建一个叫“foobar”的虚拟环境(其实对我来说更应该叫“测试环境”,或沙盒)
virtualenv foobar
3。激活这个环境,这会让foobar虚拟环境下的site-packages成为默认的版本
source foobar/bin/activate
1)foobar/bin 存放安装包的可执行文件
2)foobar/lib/python2.X/site-packages/ 存放安装包的eggs文件
建议:
virtualenv默认继承系统全局的site-packages目录,
可以将多个项目与沙盒都要用到的放在全局的site-packages里,
而其他与特定的项目关系紧密的则放在自己的环境里。
如果要将这个继承的功能取消,则在创建环境的时候,要用
virtualenv --no-site-packages foobar
4。退出虚拟环境:
deactivate
easy_install virtualenv
(运行这条命令容易出错,pip install virtualenv不会出错。
所以pip install比easy_install更好)
virtualenv dev (在当前目录下会生成dev目录)root@as3:~# virtualenv dev
显示:
New python executable in dev/bin/python
Installing Setuptools.......................................................................................
.................................................................................................
......................................done.
Installing Pip..............................................................................................
.................................................................................................
.................................................................................................
.....................................done.
root@as3:~# dev/bin/python -V
Python 2.7.6
root@as3:~# cd dev
root@as3:~/dev# ls
bin include lib
root@as3:~/dev# ls bin
activate activate.fish easy_install pip python python2.7
activate.csh activate_this.py easy_install-2.7 pip-2.7 python2
root@as3:~/dev# source bin/activate (激活dev这个环境,这会让dev虚拟环境下的site-packages成为默认的版本)
(dev)root@as3:~/dev# (运行source /root/dev/bin/activate激活虚拟环境后,提示符就由“root@as3:~/dev#”变成了
“(dev)root@as3:~/dev#”,说明现在进入了虚拟环境模式!至此,虚拟环境模式设置成功)
(dev)root@as3:~/dev# pip install hyde
会显示:
...
Successfully installed hyde fswrap commando PyYAML Markdown MarkupSafe Pygments typogrify smartypants Jinja2
Cleaning up...
(dev)root@as3:~/dev# hyde --version
hyde 0.8.8 (这次运行hyde --version终于不再出错,而且显示的hyde版本为0.8.8)
(dev)root@as3:~/dev# hyde -s hyde-site create (在当前目录下,会生成hyde-site目录)
显示:
04:14:29 hyde Creating site at [/root/dev/hyde-site] with layout [/root/dev/lib/python2.7/site-packages/hyde/layouts/basic]
04:14:29 hyde Site creation complete
(dev)root@as3:~/dev#
(dev)root@as3:~/dev# ls
bin hyde-site include lib
(dev)root@as3:~/dev# cd hyde-site
(dev)root@as3:~/dev/hyde-site# ls
content info.yaml layout README.markdown site.yaml
(dev)root@as3:~/dev/hyde-site# hyde gen (这个就是生成/更新静态网站的命令)
(dev)root@as3:~/dev/hyde-site# ls
content deploy info.yaml layout README.markdown site.yaml (新出现了deploy目录)
(dev)root@as3:~/dev/hyde-site# cd deploy
(dev)root@as3:~/dev/hyde-site/deploy# ls
about.html blog index.html portfolio
apple-touch-icon.png favicon.ico media
(dev)root@as3:~/dev/hyde-site/deploy#
(可见~/dev/hyde-site/deploy/就是静态网站的根目录)
(dev)root@as3:~/dev/hyde-site/deploy# nohup Rwebserver 45367 > /dev/null &
(访问http://as3.brite.biz:45367/,立马可看到网站效果)
发贴方法:
(dev)root@as3:~/dev/hyde-site/deploy# cd ..
(dev)root@as3:~/dev/hyde-site# ls
content deploy info.yaml layout README.markdown site.yaml
(dev)root@as3:~/dev/hyde-site# cd content
(dev)root@as3:~/dev/hyde-site/content# ls
about.html blog index.html portfolio
apple-touch-icon.png favicon.ico media
(dev)root@as3:~/dev/hyde-site/content# cd blog
(dev)root@as3:~/dev/hyde-site/content/blog# ls
angry-post.html excerpts.xml index.html sad-post.html
atom.xml happy-post.html meta.yaml tags
(dev)root@as3:~/dev/hyde-site/content/blog#
按happy-post.html的内容,新建帖子test1.html,格式如下:
---
title: test1
created: !!timestamp '2013-12-02 10:00:00'
tags:
- misc1
- misc2
---
{% mark excerpt -%}
这里写摘要。
{%- endmark %}
这里写摘要之后的正文。
然后:
(dev)root@as3:~/dev/hyde-site/content/blog# cd ~/dev/hyde-site
(dev)root@as3:~/dev/hyde-site# hyde gen
不过我发表成功的帖子http://hyde-new.brite.biz/blog/test1.html并未显示在
http://hyde-new.brite.biz/blog/页面,有点奇怪。-此问题已解决,办法:
(dev)root@as3:~/dev/hyde-site/content/blog# cd ~/dev/hyde-site
(dev)root@as3:~/dev/hyde-site# hyde gen -r (这里r是regenerate的意思)
注意:如果你之前安装过旧版的hyde-https://github.com/lakshmivyas/hyde,而你又不在virtualenv下安装新版的hyde,那么在你安装新版的hyde,并运行命令hyde -h后,你会遇到出错提示:
pkg_resources.VersionConflict: (hyde 0.8.8 (/usr/local/lib/python2.7/site-packages/hyde-0.8.8-py2.7.egg), Requirement.parse('hyde==0.5.3'))
解决办法就是进入virtualenv,安装新版的hyde,这样即可避免与旧版的hyde发生冲突。
旧版hyde的安装,请见http://briteming.blogspot.co.uk/2013/11/linux-vpspythonhyde.html
演示站点:http://hyde-new.brite.biz/index.html
http://hyde-new.brite.biz/blog/
http://hyde-new.brite.biz/blog/test1.html
http://hyde-new.brite.biz/blog/test2.html
http://hyde-new.brite.biz/blog/fengyuwuzu.html
http://hyde-new.brite.biz/blog/chinese-economy.html
项目地址:https://github.com/hyde/hyde/
https://github.com/hyde/hyde/issues/4 ----------------------------------
virtualenvwrapper
Supported Shells
virtualenvwrapper is a set of shell functions defined in Bourne shell compatible syntax. Its automated tests run under these shells on OS X and Linux:- bash
- ksh
- zsh
Windows Command Prompt
David Marble has ported virtualenvwrapper to Windows batch scripts, which can be run under Microsoft Windows Command Prompt. This is also a separately distributed re-implementation. You can download virtualenvwrapper-win from PyPI.MSYS
It is possible to use virtualenv wrapper under MSYS with a native Windows Python installation. In order to make it work, you need to define an extra environment variable named MSYS_HOME containing the root path to the MSYS installation.export WORKON_HOME=$HOME/.virtualenvs
export MSYS_HOME=/c/msys/1.0
source /usr/local/bin/virtualenvwrapper.sh
export WORKON_HOME=$HOME/.virtualenvs
export MSYS_HOME=C:\msys\1.0
source /usr/local/bin/virtualenvwrapper.sh
PowerShell
Guillermo López-Anglada has ported virtualenvwrapper to run under Microsoft’s PowerShell. We have agreed that since it is not compatible with the rest of the extensions, and is largely a re-implementation (rather than an adaptation), it should be distributed separately. You can download virtualenvwrapper-powershell from PyPI.Python Versions
virtualenvwrapper is tested under Python 2.6-3.3.Basic Installation
virtualenvwrapper should be installed into the same global site-packages area where virtualenv is installed. You may need administrative privileges to do that. The easiest way to install it is using pip:$ pip install virtualenvwrapper
$ sudo pip install virtualenvwrapper
Warning
virtualenv lets you create many different Python environments. You
should only ever install virtualenv and virtualenvwrapper on your
base Python installation (i.e. NOT while a virtualenv is active)
so that the same release is shared by all Python environments that
depend on it.
$ pip install --install-option="--user" virtualenvwrapper
Shell Startup File
Add three lines to your shell startup file (.bashrc, .profile, etc.) to set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
Lazy Loading
An alternative initialization script is provided for loading virtualenvwrapper lazily. Instead of sourcing virtualenvwrapper.sh directly, use virtualenvwrapper_lazy.sh. If virtualenvwrapper.sh is not on your $PATH, set VIRTUALENVWRAPPER_SCRIPT to point to it.export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh
Warning
When the lazy-loading version of the startup script is used,
tab-completion of arguments to virtualenvwrapper commands (such as
environment names) is not enabled until after the first command has
been run. For example, tab completion of environments does not work
for the first instance of workon.
Quick-Start
- Run: workon
- A list of environments, empty, is printed.
- Run: mkvirtualenv temp
- A new environment, temp is created and activated.
- Run: workon
- This time, the temp environment is included.
Configuration
virtualenvwrapper can be customized by changing environment variables. Set the variables in your shell startup file before loading virtualenvwrapper.sh.Location of Environments
The variable WORKON_HOME tells virtualenvwrapper where to place your virtual environments. The default is $HOME/.virtualenvs. If the directory does not exist when virtualenvwrapper is loaded, it will be created automatically.Location of Project Directories
The variable PROJECT_HOME tells virtualenvwrapper where to place your project working directories. The variable must be set and the directory created before mkproject is used.
See also
Project Linkage Filename
The variable VIRTUALENVWRAPPER_PROJECT_FILENAME tells virtualenvwrapper how to name the file linking a virtualenv to a project working directory. The default is .project.
See also
Location of Hook Scripts
The variable VIRTUALENVWRAPPER_HOOK_DIR tells virtualenvwrapper where the user-defined hooks should be placed. The default is $WORKON_HOME.
See also
Location of Hook Logs
The variable VIRTUALENVWRAPPER_LOG_FILE tells virtualenvwrapper where the logs for the hook loader should be written. The default is to not log from the hooks.Python Interpreter, virtualenv, and $PATH
During startup, virtualenvwrapper.sh finds the first python and virtualenv programs on the $PATH and remembers them to use later. This eliminates any conflict as the $PATH changes, enabling interpreters inside virtual environments where virtualenvwrapper is not installed or where different versions of virtualenv are installed. Because of this behavior, it is important for the $PATH to be set before sourcing virtualenvwrapper.sh. For example:export PATH=/usr/local/bin:$PATH
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Default Arguments for virtualenv
If the application identified by VIRTUALENVWRAPPER_VIRTUALENV needs arguments, they can be set in VIRTUALENVWRAPPER_VIRTUALENV_ARGS. The same variable can be used to set default arguments to be passed to virtualenv. For example, set the value to --no-site-packages to ensure that all new environments are isolated from the system site-packages directory.export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
Temporary Files
virtualenvwrapper creates temporary files in $TMPDIR. If the variable is not set, it uses /tmp. To change the location of temporary files just for virtualenvwrapper, set VIRTUALENVWRAPPER_TMPDIR.Site-wide Configuration
Most UNIX systems include the ability to change the configuration for all users. This typically takes one of two forms: editing the skeleton files for new accounts or editing the global startup file for a shell.Editing the skeleton files for new accounts means that each new user will have their private startup files preconfigured to load virtualenvwrapper. They can disable it by commenting out or removing those lines. Refer to the documentation for the shell and operating system to identify the appropriate file to edit.
Modifying the global startup file for a given shell means that all users of that shell will have virtualenvwrapper enabled, and they cannot disable it. Refer to the documentation for the shell to identify the appropriate file to edit.
Upgrading to 2.9
Version 2.9 includes the features previously delivered separately by virtualenvwrapper.project. If you have an older verison of the project extensions installed, remove them before upgrading.Upgrading from 1.x
The shell script containing the wrapper functions has been renamed in the 2.x series to reflect the fact that shells other than bash are supported. In your startup file, change source /usr/local/bin/virtualenvwrapper_bashrc to source /usr/local/bin/virtualenvwrapper.shfrom http://virtualenvwrapper.readthedocs.org/en/latest/install.html
----------------------------------------
http://www.virtualenv.org/en/latest/
https://github.com/pypa/virtualenv
----------------------------------------------
virtualenv的安装与使用摘要
1。安装
easy_install virtualenv
2。创建一个叫“foobar”的虚拟环境(其实对我来说更应该叫“测试环境”,或沙盒)
virtualenv foobar
3。激活这个环境,这会让foobar虚拟环境下的site-packages成为默认的版本
source foobar/bin/activate
1)foobar/bin 存放安装包的可执行文件
2)foobar/lib/python2.X/site-packages/ 存放安装包的eggs文件
建议:
virtualenv默认继承系统全局的site-packages目录,
可以将多个项目与沙盒都要用到的放在全局的site-packages里,
而其他与特定的项目关系紧密的则放在自己的环境里。
如果要将这个继承的功能取消,则在创建环境的时候,要用
virtualenv --no-site-packages foobar
4。退出虚拟环境:
deactivate