99

I know about virtualenv and pip. But these are a bit different from bundler/carton.

For instance:

  • pip writes the absolute path to shebang or activate script
  • pip doesn't have the exec sub command (bundle exec bar)
  • virtualenv copies the Python interpreter to a local directory

Does every Python developer use virtualenv/pip? Are there other package management tools for Python?

4
  • 4
    No, not every Python user uses virtualenv. I've personally never needed it.
    – Fred Foo
    Jan 4, 2012 at 11:59
  • I am not aware of something exactly like Ruby bundler (which I did not know until now, BTW). What I use to do is to use both virtualenv and pip and setuptools - or distutils or whatever distribution system I find first in Google :) I am curious about an answer as well but this is my solution most of the time.
    – brandizzi
    Jan 4, 2012 at 13:28
  • pipenv and shovel mentioned below are more modern choices since this question was asked.
    – Jim Meyer
    Jan 12, 2018 at 17:15
  • 2
    Neither pipenv nor shovel are equivalent. Shovel's nothing like bundler, more like rake. Python dependency management is quite far behind. It will be merged into pip one day though (pypi.org/project/pipfile)… Jun 15, 2020 at 15:00

8 Answers 8

76

From what i've read about bundler — pip without virtualenv should work just fine for you. You can think of it as something between regular gem command and bundler. Common things that you can do with pip:

  1. Installing packages (gem install)

    pip install mypackage
    
  2. Dependencies and bulk-install (gemfile)

    Probably the easiest way is to use pip's requirements.txt files. Basically it's just a plain list of required packages with possible version constraints. It might look something like:

    nose==1.1.2
    django<1.3
    PIL
    

    Later when you'd want to install those dependencies you would do:

    $ pip install -r requirements.txt
    

    A simple way to see all your current packages in requirements-file syntax is to do:

    $ pip freeze
    

    You can read more about it here.

  3. Execution (bundler exec)

    All python packages that come with executable files are usually directly available after install (unless you have custom setup or it's a special package). For example:

    $ pip install gunicorn
    $ gunicorn -h 
    
  4. Package gems for install from cache (bundler package)

    There is pip bundle and pip zip/unzip. But i'm not sure if many people use it.

p.s. If you do care about environment isolation you can also use virtualenv together with pip (they are close friends and work perfectly together). By default pip installs packages system-wide which might require admin rights.

5
  • 50
    The great thing about bundler is exactly that the virtualenv part is integrated and in most cases no admin rights are required. In fact, bundle may well be the only gem one needs globally. bundle install --path vendor installs everything locally and bundle exec is smart enough to figure that out. No need for explicit environment changes.
    – Debilski
    Jan 10, 2012 at 9:20
  • 12
    I don't think point #3 is correct. Simply running a ruby executable can be done with or without bundle exec. The whole point of bundle exec is that it alters the environment as per the Gemfile before running the executable. Pip has no equivalent to bundle exec, though virtualenv might. Jun 20, 2013 at 18:22
  • @SeanMackesey whenever you run activate of the virtualenv environment you immediately become inside of the environment e.g. python point to the one in the env, not globally installed one, pythonpath is correct with respect to env, all apps also run from that env. Aug 7, 2013 at 15:23
  • 12
    The main thing about bundler is it is a defacto standard now, you can pretty much guarantee that ANY ruby project of virtually any size, will have a Gemfile sat in it's root, and you can bundle install and you're good to go, or bundle --deployment and it'll just run on a server with little else to do providing the machine has the required version of ruby on it. Python simply doesn't have an equivalent. The tools are there, the cultural ubiquity isn't.
    – ocodo
    Aug 24, 2013 at 8:00
  • 1
    using pip install is equivalent to using gem install in combination with rbenv - it is OS/user level packages. While bundle and it's Gemfile is project dependencies management first of all. It have bunch of optimizations for modules storage, install, upgrade workflow in advance to plain gem workflow.
    – x'ES
    Oct 6, 2021 at 13:10
19

You can use pipenv, which has similar interface with bundler.

$ pip install pipenv

Pipenv creates virtualenv automatically and installs dependencies from Pipfile or Pipfile.lock.

$ pipenv --three           # Create virtualenv with Python3
$ pipenv install           # Install dependencies from Pipfile
$ pipenv install requests  # Install `requests` and update Pipfile
$ pipenv lock              # Generate `Pipfile.lock`
$ pipenv shell             # Run shell with virtualenv activated

You can run command with virtualenv scope like bundle exec.

$ pipenv run python3 -c "print('hello!')"
3

There is a clone pbundler.

The version that is currently in pip simply reads the requirements.txt file you already have, but is much out of date. It's also not totally equivalent: it insists on making a virtualenv. Bundler, I notice, only installs what packages are missing, and gives you the option of giving your sudo password to install into your system dirs or of restarting, which doesn't seem to be a feature of pbundler.

However, the version on git is an almost complete rewrite to be much closer to Bundler's behaviour... including having a "Cheesefile" and now not supporting requirements.txt. This is unfortunate, since requirements.txt is the de facto standard in pythonland, and there's even Offical BDFL-stamped work to standardize it. When that comes into force, you can be sure that something like pbundler will become the de facto standard. Alas, nothing quite stable yet that I know of (but I would love to be proven wrong).

1
3

Python Poetry is the closest to Ruby bundler as of 2020 (and already since 2018). It's already more than two years old, still very active, has great documentation. One might complain about curl-pipe-python-style being the recommended way of installing, but there are alternatives, e.g. homebrew on macOS.

It uses virtualenvs behind the scenes (in contrast to bundler), but it provides and uses a lock-file, takes care of sub dependencies, adheres to specified version constraints and allows automatically updating outdated packages. There's even autocompletion for your favorite shell.

With its use of a pyproject.toml file, it's also going a bit further than bundler (closer to a gemspec. It's also comparable to JavaScript's and TypeScript's npm and yarn).

Poetrify (a complementing project) helps converting projects from requirements.txt to pyproject.toml for Poetry.

The lock file can be exported to requirements.txt by poetry export -f requirements.txt > requirements.txt, if you need that for other tooling (or the unlikely case want to go back).

2

I wrote one — https://github.com/Deepwalker/pundler . On PIP its pundle, name was already taken.

It uses requirements(_\w+)?.txt files as your desired dependencies and creates frozen(_\w+)?.txt files with frozen versions.

About (_\w+)? thing — this is envs. You can create requirements_test.txt and then use PUNDLEENV=test to use this deps in your run with requirements.txt ones alongside.

And about virtualenv – you need not one, its what pundle takes from bundler in first head.

1

I'd say Shovel is worth a look. It was developed specifically to the Pythonish version of Rake. There's not a ton of commit activity on the project, but seems stable and useful.

1

You can use pipx to install and run Python Applications in Isolated Environments automatically.

You can use pipenv to create and manage a virtualenv for your projects automatically.

Both wraps pip with virtual environment tools and aiming for different use cases.

All of these are one of the most stared project listed in the github PyPA repository.

FYI: Debian bullseye/testing currently lacks pipx. But package from sid should work fine. (2021-06-19)

0

No, no all the developers use virtualenv and/or pip, but many developers use/prefer these tools

And now, for package development tools and diferent environments that is your real question. Exist any other tools like Buildout (http://www.buildout.org/en/latest/) for the same purpose, isolate your environment Python build system for every project that you manage. For some time I use this, but not now.

Independent environments per project, in Python are a little different that the same situation in Ruby. In my case i use pyenv (https://github.com/yyuu/pyenv) that is something like rbenv but, for Python. diferent versions of python and virtualenvs per project, and, in this isolated environments, i can use pip or easy-install (if is needed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.