mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,2 +1,9 @@
|
|||||||
docs/_build
|
docs/_build
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
# Ignore irrelevant files from the Sublime Text editor
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-project
|
||||||
|
|
||||||
|
# Ignore .hgignore for contributors using Mercurial.
|
||||||
|
.hgignore
|
||||||
|
|||||||
+31
-20
@@ -1,17 +1,17 @@
|
|||||||
Virtual Environments
|
Virtual Environments
|
||||||
====================
|
====================
|
||||||
|
|
||||||
A Virtual Environment, put simply, is an isolated working copy of Python which
|
A Virtual Environment, put simply, is an isolated working copy of Python which
|
||||||
allows you to work on a specific project without worry of affecting other
|
allows you to work on a specific project without worry of affecting other
|
||||||
projects.
|
projects.
|
||||||
|
|
||||||
For example, you can work on a project which requires Django 1.3 while also
|
For example, you can work on a project which requires Django 1.3 while also
|
||||||
maintaining a project which requires Django 1.0.
|
maintaining a project which requires Django 1.0.
|
||||||
|
|
||||||
virtualenv
|
virtualenv
|
||||||
----------
|
----------
|
||||||
|
|
||||||
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create
|
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create
|
||||||
isolated Python environments.
|
isolated Python environments.
|
||||||
|
|
||||||
Install it via pip:
|
Install it via pip:
|
||||||
@@ -29,7 +29,7 @@ Basic Usage
|
|||||||
|
|
||||||
$ virtualenv venv
|
$ virtualenv venv
|
||||||
|
|
||||||
This creates a copy of Python in whichever directory you ran the command in,
|
This creates a copy of Python in whichever directory you ran the command in,
|
||||||
placing it in a folder named ``venv``.
|
placing it in a folder named ``venv``.
|
||||||
|
|
||||||
2. To begin using the virtual environment, it needs to be activated:
|
2. To begin using the virtual environment, it needs to be activated:
|
||||||
@@ -38,30 +38,30 @@ placing it in a folder named ``venv``.
|
|||||||
|
|
||||||
$ source venv/bin/activate
|
$ source venv/bin/activate
|
||||||
|
|
||||||
You can then begin installing any new modules without affecting the system
|
You can then begin installing any new modules without affecting the system
|
||||||
default Python or other virtual environments.
|
default Python or other virtual environments.
|
||||||
|
|
||||||
3. If you are done working in the virtual environment for the moment, you can
|
3. If you are done working in the virtual environment for the moment, you can
|
||||||
deactivate it:
|
deactivate it:
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
$ deactivate
|
$ deactivate
|
||||||
|
|
||||||
This puts you back to the system's default Python interpreter with all its
|
This puts you back to the system's default Python interpreter with all its
|
||||||
installed libraries.
|
installed libraries.
|
||||||
|
|
||||||
To delete a virtual environment, just delete its folder.
|
To delete a virtual environment, just delete its folder.
|
||||||
|
|
||||||
After a while, though, you might end up with a lot of virtual environments
|
After a while, though, you might end up with a lot of virtual environments
|
||||||
littered across your system, and its possible you'll forget their names or
|
littered across your system, and its possible you'll forget their names or
|
||||||
where they were placed.
|
where they were placed.
|
||||||
|
|
||||||
virtualenvwrapper
|
virtualenvwrapper
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
`virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_
|
`virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_
|
||||||
provides a set of commands which makes working with virtual environments much
|
provides a set of commands which makes working with virtual environments much
|
||||||
more pleasant. It also places all your virtual environments in one place.
|
more pleasant. It also places all your virtual environments in one place.
|
||||||
|
|
||||||
To install (make sure **virtualenv** is already installed):
|
To install (make sure **virtualenv** is already installed):
|
||||||
@@ -74,6 +74,17 @@ To install (make sure **virtualenv** is already installed):
|
|||||||
|
|
||||||
(`Full virtualenvwrapper install instructions <http://www.doughellmann.com/docs/virtualenvwrapper/#introduction>`_.)
|
(`Full virtualenvwrapper install instructions <http://www.doughellmann.com/docs/virtualenvwrapper/#introduction>`_.)
|
||||||
|
|
||||||
|
For Windows, you can use the `virtualenvwrapper-powershell <https://bitbucket.org/guillermooo/virtualenvwrapper-powershell>`_ clone.
|
||||||
|
|
||||||
|
To install (make sure **virtualenv** is already installed):
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
PS> pip install virtualenvwrapper-powershell
|
||||||
|
PS> $env:WORKON_HOME="~/Envs"
|
||||||
|
PS> mkdir $env:WORKON_HOME
|
||||||
|
PS> import-module virtualenvwrapper
|
||||||
|
|
||||||
Basic Usage
|
Basic Usage
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
@@ -83,7 +94,7 @@ Basic Usage
|
|||||||
|
|
||||||
$ mkvirtualenv venv
|
$ mkvirtualenv venv
|
||||||
|
|
||||||
This creates the ``venv`` folder inside ``~/Envs``.
|
This creates the ``venv`` folder inside ``~/Envs``.
|
||||||
|
|
||||||
2. Work on a virtual environment:
|
2. Work on a virtual environment:
|
||||||
|
|
||||||
@@ -91,10 +102,10 @@ This creates the ``venv`` folder inside ``~/Envs``.
|
|||||||
|
|
||||||
$ workon venv
|
$ workon venv
|
||||||
|
|
||||||
**virtualenvwrapper** provides tab-completion on environment names. It really
|
**virtualenvwrapper** provides tab-completion on environment names. It really
|
||||||
helps when you have a lot of environments and have trouble remembering their
|
helps when you have a lot of environments and have trouble remembering their
|
||||||
names.
|
names.
|
||||||
``workon`` also deactivates whatever environment you are currently in, so you
|
``workon`` also deactivates whatever environment you are currently in, so you
|
||||||
can quickly switch between environments.
|
can quickly switch between environments.
|
||||||
|
|
||||||
3. Deactivating is still the same:
|
3. Deactivating is still the same:
|
||||||
@@ -116,8 +127,8 @@ Other useful commands
|
|||||||
List all of the environments.
|
List all of the environments.
|
||||||
|
|
||||||
``cdvirtualenv``
|
``cdvirtualenv``
|
||||||
Navigate into the directory of the currently activated virtual environment,
|
Navigate into the directory of the currently activated virtual environment,
|
||||||
so you can browse its ``site-packages``, for example.
|
so you can browse its ``site-packages``, for example.
|
||||||
|
|
||||||
``cdsitepackages``
|
``cdsitepackages``
|
||||||
Like the above, but directly into ``site-packages`` directory.
|
Like the above, but directly into ``site-packages`` directory.
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
REM Command file for Sphinx documentation
|
||||||
|
|
||||||
|
if "%SPHINXBUILD%" == "" (
|
||||||
|
set SPHINXBUILD=sphinx-build
|
||||||
|
)
|
||||||
|
set BUILDDIR=build
|
||||||
|
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% docs
|
||||||
|
if NOT "%PAPER%" == "" (
|
||||||
|
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "" goto help
|
||||||
|
|
||||||
|
if "%1" == "help" (
|
||||||
|
:help
|
||||||
|
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||||
|
echo. html to make standalone HTML files
|
||||||
|
echo. dirhtml to make HTML files named index.html in directories
|
||||||
|
echo. singlehtml to make a single large HTML file
|
||||||
|
echo. pickle to make pickle files
|
||||||
|
echo. json to make JSON files
|
||||||
|
echo. htmlhelp to make HTML files and a HTML help project
|
||||||
|
echo. qthelp to make HTML files and a qthelp project
|
||||||
|
echo. devhelp to make HTML files and a Devhelp project
|
||||||
|
echo. epub to make an epub
|
||||||
|
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||||
|
echo. text to make text files
|
||||||
|
echo. man to make manual pages
|
||||||
|
echo. changes to make an overview over all changed/added/deprecated items
|
||||||
|
echo. linkcheck to check all external links for integrity
|
||||||
|
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "clean" (
|
||||||
|
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||||
|
del /q /s %BUILDDIR%\*
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "html" (
|
||||||
|
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "dirhtml" (
|
||||||
|
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "singlehtml" (
|
||||||
|
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "pickle" (
|
||||||
|
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||||
|
echo.
|
||||||
|
echo.Build finished; now you can process the pickle files.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "json" (
|
||||||
|
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||||
|
echo.
|
||||||
|
echo.Build finished; now you can process the JSON files.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "htmlhelp" (
|
||||||
|
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||||
|
echo.
|
||||||
|
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||||
|
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "qthelp" (
|
||||||
|
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||||
|
echo.
|
||||||
|
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||||
|
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||||
|
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\SublimeDocs.qhcp
|
||||||
|
echo.To view the help file:
|
||||||
|
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\SublimeDocs.ghc
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "devhelp" (
|
||||||
|
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||||
|
echo.
|
||||||
|
echo.Build finished.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "epub" (
|
||||||
|
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "latex" (
|
||||||
|
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||||
|
echo.
|
||||||
|
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "text" (
|
||||||
|
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "man" (
|
||||||
|
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||||
|
echo.
|
||||||
|
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "changes" (
|
||||||
|
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||||
|
echo.
|
||||||
|
echo.The overview file is in %BUILDDIR%/changes.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "linkcheck" (
|
||||||
|
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||||
|
echo.
|
||||||
|
echo.Link check complete; look for any errors in the above output ^
|
||||||
|
or in %BUILDDIR%/linkcheck/output.txt.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "doctest" (
|
||||||
|
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||||
|
echo.
|
||||||
|
echo.Testing of doctests in the sources finished, look at the ^
|
||||||
|
results in %BUILDDIR%/doctest/output.txt.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
:end
|
||||||
Reference in New Issue
Block a user