···8899Several versions of the Python interpreter are available on Nix, as well as a
1010high amount of packages. The attribute `python3` refers to the default
1111-interpreter, which is currently CPython 3.9. The attribute `python` refers to
1111+interpreter, which is currently CPython 3.10. The attribute `python` refers to
1212CPython 2.7 for backwards-compatibility. It is also possible to refer to
1313-specific versions, e.g. `python38` refers to CPython 3.8, and `pypy` refers to
1313+specific versions, e.g. `python39` refers to CPython 3.9, and `pypy` refers to
1414the default PyPy interpreter.
15151616Python is used a lot, and in different ways. This affects also how it is
···2626The interpreters have several common attributes. One of these attributes is
2727`pkgs`, which is a package set of Python libraries for this specific
2828interpreter. E.g., the `toolz` package corresponding to the default interpreter
2929-is `python.pkgs.toolz`, and the CPython 3.8 version is `python38.pkgs.toolz`.
2929+is `python.pkgs.toolz`, and the CPython 3.9 version is `python39.pkgs.toolz`.
3030The main package set contains aliases to these package sets, e.g.
3131-`pythonPackages` refers to `python.pkgs` and `python38Packages` to
3232-`python38.pkgs`.
3131+`pythonPackages` refers to `python.pkgs` and `python39Packages` to
3232+`python39.pkgs`.
33333434#### Installing Python and packages {#installing-python-and-packages}
3535···5454executables are wrapped to be able to find each other and all of the modules.
55555656In the following examples we will start by creating a simple, ad-hoc environment
5757-with a nix-shell that has `numpy` and `toolz` in Python 3.8; then we will create
5757+with a nix-shell that has `numpy` and `toolz` in Python 3.9; then we will create
5858a re-usable environment in a single-file Python script; then we will create a
5959full Python environment for development with this same environment.
6060···7070their runtime dependencies), with no other Python packages in the Python
7171interpreter's scope.
72727373-To create a Python 3.8 session with `numpy` and `toolz` available, run:
7373+To create a Python 3.9 session with `numpy` and `toolz` available, run:
74747575```sh
7676-$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy toolz ])'
7676+$ nix-shell -p 'python39.withPackages(ps: with ps; [ numpy toolz ])'
7777```
78787979By default `nix-shell` will start a `bash` session with this interpreter in our
···81818282```Python console
8383[nix-shell:~/src/nixpkgs]$ python3
8484-Python 3.8.1 (default, Dec 18 2019, 19:06:26)
8585-[GCC 9.2.0] on linux
8484+Python 3.9.12 (main, Mar 23 2022, 21:36:19)
8585+[GCC 11.3.0] on linux
8686Type "help", "copyright", "credits" or "license" for more information.
8787>>> import numpy; import toolz
8888```
···102102directly like so:
103103104104```sh
105105-$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy toolz requests ])' --run python3
106106-these derivations will be built:
107107- /nix/store/xbdsrqrsfa1yva5s7pzsra8k08gxlbz1-python3-3.8.1-env.drv
108108-building '/nix/store/xbdsrqrsfa1yva5s7pzsra8k08gxlbz1-python3-3.8.1-env.drv'...
109109-created 277 symlinks in user environment
110110-Python 3.8.1 (default, Dec 18 2019, 19:06:26)
111111-[GCC 9.2.0] on linux
105105+$ nix-shell -p "python39.withPackages (ps: with ps; [ numpy toolz requests ])" --run python3
106106+this derivation will be built:
107107+ /nix/store/mpn7k6bkjl41fm51342rafaqfsl10qs4-python3-3.9.12-env.drv
108108+this path will be fetched (0.09 MiB download, 0.41 MiB unpacked):
109109+ /nix/store/5gaiacnzi096b6prc6aa1pwrhncmhc8b-python3.9-toolz-0.11.2
110110+copying path '/nix/store/5gaiacnzi096b6prc6aa1pwrhncmhc8b-python3.9-toolz-0.11.2' from 'https://cache.nixos.org'...
111111+building '/nix/store/mpn7k6bkjl41fm51342rafaqfsl10qs4-python3-3.9.12-env.drv'...
112112+created 279 symlinks in user environment
113113+Python 3.9.12 (main, Mar 23 2022, 21:36:19)
114114+[GCC 11.3.0] on linux
112115Type "help", "copyright", "credits" or "license" for more information.
113116>>> import requests
114117>>>
···147150in the previous section, we could startup a shell and just run it like so:
148151149152```ShellSession
150150-$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'
153153+$ nix-shell -p 'python39.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'
151154The dot product of [1 2] and [3 4] is: 11
152155```
153156···210213development we're usually working in an entire package repository.
211214212215As explained in the Nix manual, `nix-shell` can also load an expression from a
213213-`.nix` file. Say we want to have Python 3.8, `numpy` and `toolz`, like before,
216216+`.nix` file. Say we want to have Python 3.9, `numpy` and `toolz`, like before,
214217in an environment. We can add a `shell.nix` file describing our dependencies:
215218216219```nix
217220with import <nixpkgs> {};
218218-(python38.withPackages (ps: [ps.numpy ps.toolz])).env
221221+(python39.withPackages (ps: [ps.numpy ps.toolz])).env
219222```
220223221224And then at the command line, just typing `nix-shell` produces the same
···229232 imports the `<nixpkgs>` function, `{}` calls it and the `with` statement
230233 brings all attributes of `nixpkgs` in the local scope. These attributes form
231234 the main package set.
232232-2. Then we create a Python 3.8 environment with the `withPackages` function, as before.
235235+2. Then we create a Python 3.9 environment with the `withPackages` function, as before.
2332363. The `withPackages` function expects us to provide a function as an argument
234237 that takes the set of all Python packages and returns a list of packages to
235238 include in the environment. Here, we select the packages `numpy` and `toolz`
···240243```nix
241244with import <nixpkgs> {};
242245let
243243- pythonEnv = python38.withPackages (ps: [
246246+ pythonEnv = python39.withPackages (ps: [
244247 ps.numpy
245248 ps.toolz
246249 ]);
···378381379382An expression for `toolz` can be found in the Nixpkgs repository. As explained
380383in the introduction of this Python section, a derivation of `toolz` is available
381381-for each interpreter version, e.g. `python38.pkgs.toolz` refers to the `toolz`
382382-derivation corresponding to the CPython 3.8 interpreter.
384384+for each interpreter version, e.g. `python39.pkgs.toolz` refers to the `toolz`
385385+derivation corresponding to the CPython 3.9 interpreter.
383386384387The above example works when you're directly working on
385388`pkgs/top-level/python-packages.nix` in the Nixpkgs repository. Often though,
···392395with import <nixpkgs> {};
393396394397( let
395395- my_toolz = python38.pkgs.buildPythonPackage rec {
398398+ my_toolz = python39.pkgs.buildPythonPackage rec {
396399 pname = "toolz";
397400 version = "0.10.0";
398401399399- src = python38.pkgs.fetchPypi {
402402+ src = python39.pkgs.fetchPypi {
400403 inherit pname version;
401404 sha256 = "08fdd5ef7c96480ad11c12d472de21acd32359996f69a5259299b540feba4560";
402405 };
···414417```
415418416419Executing `nix-shell` will result in an environment in which you can use
417417-Python 3.8 and the `toolz` package. As you can see we had to explicitly mention
420420+Python 3.9 and the `toolz` package. As you can see we had to explicitly mention
418421for which Python version we want to build a package.
419422420423So, what did we do here? Well, we took the Nix expression that we used earlier
···742745is a local source, and if the local source has a `setup.py`, then development
743746mode is activated.
744747745745-In the following example we create a simple environment that has a Python 3.8
748748+In the following example we create a simple environment that has a Python 3.9
746749version of our package in it, as well as its dependencies and other packages we
747750like to have in the environment, all specified with `propagatedBuildInputs`.
748751Indeed, we can just add any package we like to have in our environment to
···750753751754```nix
752755with import <nixpkgs> {};
753753-with python38Packages;
756756+with python39Packages;
754757755758buildPythonPackage rec {
756759 name = "mypackage";
···828831829832### Interpreters {#interpreters}
830833831831-Versions 2.7, 3.7, 3.8 and 3.9 of the CPython interpreter are available as
832832-respectively `python27`, `python37`, `python38` and `python39`. The
833833-aliases `python2` and `python3` correspond to respectively `python27` and
834834+Versions 2.7, 3.7, 3.8, 3.9 and 3.10 of the CPython interpreter are available
835835+as respectively `python27`, `python37`, `python38`, `python39` and `python310`.
836836+The aliases `python2` and `python3` correspond to respectively `python27` and
834837`python39`. The attribute `python` maps to `python2`. The PyPy interpreters
835838compatible with Python 2.7 and 3 are available as `pypy27` and `pypy3`, with
836839aliases `pypy2` mapping to `pypy27` and `pypy` mapping to `pypy2`. The Nix
···991010 sourceRoot = "source/runtime/Python3";
11111212+ # in 4.9, test was renamed to tests
1213 checkPhase = ''
1313- cd test
1414+ cd test*
1415 ${python.interpreter} ctest.py
1516 '';
1617
···11+diff --git a/selectors2.py b/selectors2.py
22+index 1625a30..c4a1231 100644
33+--- a/selectors2.py
44++++ b/selectors2.py
55+@@ -22,7 +22,8 @@
66+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
77+ # SOFTWARE.
88+99+-from collections import namedtuple, Mapping
1010++from collections import namedtuple
1111++from collections.abc import Mapping
1212+ import errno
1313+ import math
1414+ import platform
···1442514425 # available as `pythonPackages.tkinter` and can be used as any other Python package.
1442614426 # When switching these sets, please update docs at ../../doc/languages-frameworks/python.md
1442714427 python2 = python27;
1442814428- python3 = python39;
1442814428+ python3 = python310;
14429144291443014430 # pythonPackages further below, but assigned here because they need to be in sync
1443114431 python2Packages = dontRecurseIntoAttrs python27Packages;
1443214432- python3Packages = dontRecurseIntoAttrs python39Packages;
1443214432+ python3Packages = dontRecurseIntoAttrs python310Packages;
14433144331443414434 pypy = pypy2;
1443514435 pypy2 = pypy27;
···1446814468 python39Full = python39.override {
1446914469 self = python39Full;
1447014470 pythonAttr = "python39Full";
1447114471+ bluezSupport = true;
1447214472+ x11Support = true;
1447314473+ };
1447414474+ python310Full = python310.override {
1447514475+ self = python310Full;
1447614476+ pythonAttr = "python310Full";
1447114477 bluezSupport = true;
1447214478 x11Support = true;
1447314479 };
···26058260642605926065 eq10q = callPackage ../applications/audio/eq10q { };
26060260662606126061- errbot = python3Packages.callPackage ../applications/networking/errbot { };
2606726067+ errbot = callPackage ../applications/networking/errbot { };
26062260682606326069 espeak-classic = callPackage ../applications/audio/espeak { };
2606426070
+1
pkgs/top-level/python-aliases.nix
···9797 mailman-web = throw "Please use pkgs.mailman-web"; # added 2022-04-29
9898 net2grid = gridnet; # add 2022-04-22
9999 nose-cover3 = throw "nose-cover3 has been removed, it was using setuptools 2to3 translation feature, which has been removed in setuptools 58"; # added 2022-02-16
100100+ ordereddict = throw "ordereddict has been removed because it is only useful on unsupported python versions."; # added 2022-05-28
100101 pam = python-pam; # added 2020-09-07.
101102 PasteDeploy = pastedeploy; # added 2021-10-07
102103 pathpy = path; # added 2022-04-12