DEV Community

Ghost
Ghost

Posted on

pnpm, but for Python?

Does anything like pnpm exist for Python? I'm looking for something like virtualenv but which uses symlinks instead of installing packages in the project directory, and that re-uses a local install directory so I could theoretically bootstrap new projects without network access.

Top comments (5)

Collapse
 
rhymes profile image
rhymes

Mmm nice question.

I don't know if there's an easy way.

You could use bandersnatch to create an offline mirror of PyPI and then point pipenv to such mirror

Collapse
 
nl_p_ profile image
Nor • Edited
  • Maybe Conda.

    • you can create .conda folder under your project. \ Vscode supports it, just like you do with .venv: install conda > click python version interpreter on bottom right > click create virtual env > choose .conda instead of .venv \ Or do it with terminal conda create --prefix ./.conda python=3.11
  - _(I was using pip venv before, then I came to search for this, tried poetry that has the same problem, kept asking and was guided back to check conda.)_
    _(cant find any on stackoverflow, the only github didnt allow to answer.)

  - References:

    pnpm like installation mode to save space · Issue #3487 · python-poetry/poetry
    https://github.com/python-poetry/poetry/issues/3487

    python - Does anaconda support hardlink in Windows? - Stack Overflow
    https://stackoverflow.com/questions/75657317/does-anaconda-support-hardlink-in-windows

    pnpm for Python · pnpm · Discussion #3164
    https://github.com/orgs/pnpm/discussions/3164

    - $>"
      - **Use conda environments for isolation**
      - - Create a conda environment to isolate any changes pip makes.
        - Environments take up little space thanks to hard links.
      <$
      https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

    - $>"
      There’s not a whole lot to this. [Conda tries to use hard links whenever possible](https://github.com/conda/conda/blob/4.6.7/conda/gateways/disk/create.py#L297-L337). Hard links increase the reference count on disk to a specific file, without actually copying its contents.
      <$
      https://www.anaconda.com/blog/understanding-and-improving-condas-performance
Enter fullscreen mode Exit fullscreen mode
  • Or uv or pixi, I think they have hardlinks too.
Collapse
 
zkochan profile image
Zoltan Kochan • Edited

Could we make pnpm work for Python?

Collapse
 
allison_seboldt profile image
Allison Seboldt

It sounds like you want pip pip.pypa.io/en/stable/

Collapse
 
raulinlee profile image
Lee Raulin

Hmm... The main advantage of pnpn is that it will only ever store one copy on your hard drive for each library per version number, no matter what.

IOW, if it does not have a local copy of the version of the library you want, it downloads one and only one. Thereafter, every time you "install" that version of that library for a project, it just creates a symlink. This saves gigabytes, depending on how many projects you have.

(JS/Node doesn't have "virtual environments", but basically any time you install anything with npm without using the -g ("global") flag, it's effectively installed to a virtual environment for the project.)

As far as I know, pip doesn't do anything like that. It's just like npm--if you use a virtual env for every project, and lib-x v 1.0.3 is 5 Mb, and you install it for two projects, you now have 10 Mb less space. 3 projects, and it's 15 Mb, etc.

Of course, you could just install the lib globally, and have all your projects use that copy... Exactly like npm.