# Why is the nix-compiled Python slower?

**URL:** https://discourse.nixos.org/t/why-is-the-nix-compiled-python-slower/18717
**Category:** Help
**Created:** [April 19, 2022, 10:40pm UTC](https://discourse.nixos.org/t/why-is-the-nix-compiled-python-slower/18717 "2022-04-19T22:40:37Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![knedlsepp](https://discourse.nixos.org/user_avatar/discourse.nixos.org/knedlsepp/32/532_2.png) [@knedlsepp](https://discourse.nixos.org/u/knedlsepp)
#### Post date: [April 21, 2022, 8:05pm UTC](https://discourse.nixos.org/t/why-is-the-nix-compiled-python-slower/18717/10 "2022-04-21T20:05:17Z")

</div>

Here’s an example `default.nix` that you can put in your project and use `nix-shell`.

```auto
{ nixpkgs ? (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/ba02fd0434ed92b7335f17c97af689b9db1413e0.tar.gz";
    sha256 = "1pjx78qb3k4cjkbwiw9v0wd545h48fj4criazijwds53l0q4dzn1";
  })
, src ? builtins.fetchGit ./.
}:
let
  pkgs = import nixpkgs { };
  python38Optimized = pkgs.python38.override {
    enableOptimizations = true;
    reproducibleBuild = false;
    self = python38Optimized;
  };
  pyPkgs = python38Optimized.pkgs;
in
python38Optimized.pkgs.buildPythonPackage rec {
  name = "python-example";
  inherit src;
  propagatedBuildInputs = with pyPkgs; [
    numpy
  ];
  nativeBuildInputs = with pyPkgs; pkgs.lib.optionals (pkgs.lib.inNixShell) [
    ipython
  ];
}

```

Notes:

- The expression requires the directory to be versioned with `git`
- Fetch a hot beverage while it compiles Python 3.8 for you on the first launch

---

_[View the full topic](https://discourse.nixos.org/t/why-is-the-nix-compiled-python-slower/18717)._
