Python: Difference between revisions
imported>Asymmetric Add application example |
imported>Krey No edit summary |
||
| Line 1: | Line 1: | ||
== Installation == | |||
The Python packages available to the interpreter must be declared when installing Python. | |||
Supposing you want Python 3 with <code>pandas</code> and <code>requests</code>, then <code>configuration.nix</code> should then look something like | |||
<syntaxhighlight lang="nix"> | |||
environment.systemPackages = | |||
let myPythonPackages = pythonPackages: with pythonPackages; [ | |||
pandas | |||
requests | |||
# other python packages you want | |||
]; | |||
in | |||
with pkgs; [ | |||
# all your other (non-Python) packages | |||
(python3.withPackages myPythonPackages) | |||
] | |||
</syntaxhighlight> | |||
There are several versions of Python available. Replace <code>python3</code> with <code>python2</code> or <code>pypy</code> in the above snippet according to your needs. | |||
=== Explanation (optional) === | |||
We defined a function <code>myPythonPackages</code> which takes as input a set, <code>pythonPackages</code> and returns a list of attributes thereof. | |||
=== Dealing with missing/outdated packages === | |||
Add <code>virtualenvwrapper</code> to your list of Python packages above. You can use pip safely inside such a virtualenv, most pure Python packages should work. | |||
<syntaxhighlight lang="shell"> | |||
virtualenv my-new-python-venv | |||
source my-new-python-venv/bin/activate | |||
pip install pandas_datareader # or some other package you want | |||
</syntaxhighlight> | |||
This, of course, goes against the declarative nature of the rest of the configuration and should be avoided if possible. | |||
== Contribution guidelines == | == Contribution guidelines == | ||