mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Mark up files & directories
This commit is contained in:
@@ -47,7 +47,7 @@ The script will explain what changes it will make and prompt you before the
|
||||
installation begins.
|
||||
Once you've installed Homebrew, insert the Homebrew directory at the top
|
||||
of your ``PATH`` environment variable. You can do this by adding the following
|
||||
line at the bottom of your ``~/.bashrc`` file
|
||||
line at the bottom of your :file:`~/.bashrc` file
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ double-click the file. The MSI package format allows Windows administrators to
|
||||
automate installation with their standard tools.
|
||||
|
||||
By design, Python installs to a directory with the version number embedded,
|
||||
e.g. Python version 2.7 will install at ``C:\Python27\``, so that you can
|
||||
e.g. Python version 2.7 will install at :file:`C:\Python27\`, so that you can
|
||||
have multiple versions of Python on the
|
||||
same system without conflicts. Of course, only one interpreter can be the
|
||||
default application for Python file types. It also does not automatically
|
||||
@@ -22,7 +22,7 @@ which copy of Python is run.
|
||||
|
||||
Typing the full path name for a Python interpreter each time quickly gets
|
||||
tedious, so add the directories for your default Python version to the PATH.
|
||||
Assuming that your Python installation is in ``C:\Python27\``, add this to your
|
||||
Assuming that your Python installation is in :file:`C:\Python27\`, add this to your
|
||||
PATH:
|
||||
|
||||
.. code-block:: console
|
||||
@@ -35,7 +35,7 @@ You can do this easily by running the following in ``powershell``:
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
|
||||
|
||||
The second (``Scripts``) directory receives command files when certain
|
||||
The second (:file:`Scripts`) directory receives command files when certain
|
||||
packages are installed, so it is a very useful addition.
|
||||
You do not need to install or configure anything else to use Python. Having
|
||||
said that, I would strongly recommend that you install the tools and libraries
|
||||
@@ -92,14 +92,14 @@ project's directory
|
||||
|
||||
> virtualenv venv
|
||||
|
||||
To use an environment, run the ``activate.bat`` batch file in the ``Scripts``
|
||||
To use an environment, run the :file:`activate.bat` batch file in the :file:`Scripts`
|
||||
subdirectory of that environment. Your command prompt will change to show the
|
||||
active environment. Once you have finished working in the current virtual
|
||||
environment, run the ``deactivate.bat`` batch file to restore your settings to
|
||||
environment, run the :file:`deactivate.bat` batch file to restore your settings to
|
||||
normal.
|
||||
|
||||
Each new environment automatically includes a copy of ``pip`` in the
|
||||
``Scripts`` subdirectory, so that you can setup the third-party libraries and
|
||||
:file:`Scripts` subdirectory, so that you can setup the third-party libraries and
|
||||
tools that you want to use in that environment. Put your own code within a
|
||||
subdirectory of the environment, however you wish. When you no longer need a
|
||||
particular environment, simply copy your code out of it, and then delete the
|
||||
|
||||
@@ -18,13 +18,13 @@ project. Over time this can result in a messy global package list.
|
||||
|
||||
In order to make sure that you install packages to your active virtual environment
|
||||
when you use ``pip install``, consider adding the following two lines to your
|
||||
``~/.bashrc`` file:
|
||||
:file:`~/.bashrc` file:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
export PIP_REQUIRE_VIRTUALENV=true
|
||||
|
||||
After saving this change and sourcing the ``~/.bashrc`` file with ``source ~/.bashrc``,
|
||||
After saving this change and sourcing the :file:`~/.bashrc` file with ``source ~/.bashrc``,
|
||||
pip will no longer let you install packages if you are not in a virtual environment.
|
||||
If you try to use ``pip install`` outside of a virtual environment pip will gently
|
||||
remind you that an activated virtual environment is needed to install packages.
|
||||
@@ -34,22 +34,22 @@ remind you that an activated virtual environment is needed to install packages.
|
||||
$ pip install requests
|
||||
Could not find an activated virtualenv (required).
|
||||
|
||||
You can also do this configuration by editing your ``pip.conf`` or ``pip.ini``
|
||||
file. ``pip.conf`` is used by Unix and Mac OS X operating systems and it can be
|
||||
You can also do this configuration by editing your :file:`pip.conf` or :file:`pip.ini`
|
||||
file. :file:`pip.conf` is used by Unix and Mac OS X operating systems and it can be
|
||||
found at:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$HOME/.pip/pip.conf
|
||||
|
||||
Similarly, the ``pip.ini`` file is used by Windows operating systems and it can
|
||||
Similarly, the :file:`pip.ini` file is used by Windows operating systems and it can
|
||||
be found at:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
%HOME%\pip\pip.ini
|
||||
|
||||
If you don't have a ``pip.conf`` or ``pip.ini`` file at these locations, you can
|
||||
If you don't have a :file:`pip.conf` or :file:`pip.ini` file at these locations, you can
|
||||
create a new file with the correct name for your operating system.
|
||||
|
||||
If you already have a configuration file, just add the following line under the
|
||||
@@ -70,7 +70,7 @@ add the following lines to this new file:
|
||||
|
||||
You will of course need to install some packages globally (usually ones that you
|
||||
use across different projects consistenly) and this can be accomplished by adding
|
||||
the following to your ``~/.bashrc`` file:
|
||||
the following to your :file:`~/.bashrc` file:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
@@ -78,7 +78,7 @@ the following to your ``~/.bashrc`` file:
|
||||
PIP_REQUIRE_VIRTUALENV="" pip "$@"
|
||||
}
|
||||
|
||||
After saving the changes and sourcing your ``~/.bashrc`` file you can now install
|
||||
After saving the changes and sourcing your :file:`~/.bashrc` file you can now install
|
||||
packages globally by running ``gpip install``. You can change the name of the
|
||||
function to anything you like, just keep in mind that you will have to use that
|
||||
name when trying to install packages globally with pip.
|
||||
@@ -96,7 +96,7 @@ start working on a new project (and in a new virtual environmen as a result).
|
||||
Fortunately, you can configure pip in such a way that it tries to reuse already
|
||||
installed packages.
|
||||
|
||||
On UNIX systems, you can add the following line to your ``.bashrc`` or ``.bash_profile``
|
||||
On UNIX systems, you can add the following line to your :file:`.bashrc` or :file:`.bash_profile`
|
||||
file.
|
||||
|
||||
.. code-block:: console
|
||||
@@ -104,25 +104,25 @@ file.
|
||||
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
|
||||
|
||||
You can set the path to anywhere you like (as long as you have write
|
||||
access). After adding this line, ``source`` your ``.bashrc`` (or ``.bash_profile``)
|
||||
access). After adding this line, ``source`` your :file:`.bashrc` (or :file:`.bash_profile`)
|
||||
file and you will be all set.
|
||||
|
||||
Another way of doing the same configuration is via the ``pip.conf`` or ``pip.ini``
|
||||
Another way of doing the same configuration is via the :file:`pip.conf` or :file:`pip.ini`
|
||||
files, depending on your system. If you are on Windows, you can add the following
|
||||
line to your ``pip.ini`` file under ``[global]`` settings:
|
||||
line to your :file:`pip.ini` file under ``[global]`` settings:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
download-cache = %HOME%\pip\cache
|
||||
|
||||
Similarly, on UNIX systems you should simply add the following line to your
|
||||
``pip.conf`` file under ``[global]`` settings:
|
||||
:file:`pip.conf` file under ``[global]`` settings:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
download-cache = $HOME/.pip/cache
|
||||
|
||||
Even though you can use any path you like to store your cache, it is recommended
|
||||
that you create a new folder *in* the folder where your ``pip.conf`` or ``pip.ini``
|
||||
that you create a new folder *in* the folder where your :file:`pip.conf` or :file:`pip.ini`
|
||||
file lives. If you don't trust yourself with all of this path voodoo, just use
|
||||
the values provided here and you will be fine.
|
||||
|
||||
Reference in New Issue
Block a user