Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Python equivalents to Ruby's bundler / Perl's carton?

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?

like image 622
riywo Avatar asked Jan 04 '12 11:01

riywo


2 Answers

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.

like image 71
Denys Shabalin Avatar answered Sep 29 '22 18:09

Denys Shabalin


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!')" 
like image 32
nonylene Avatar answered Sep 29 '22 18:09

nonylene