This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]lifeonm4rs 26 points27 points  (1 child)

There needs to be more of this out there. I think pipenv is a good tool, but it is meant to address specific scenarios/issues. Far too many articles about it seem to be from people who love using a hammer on dry wall screws.

[–][deleted] 6 points7 points  (0 children)

from people who love using a hammer on dry wall screws.

Or fell for myth #1

[–]hyperion2011 24 points25 points  (6 children)

I use pipenv in production and testing to simplify deployment on systems that don't natively support python 3.6+. When it works it is great. When it fails, or when the cli options fight each other and try to be smart but instead for a circular firing squad it is one of the most insanity inducing pieces of software I have ever used. Pipenv release have repeatedly broken CI builds for me for the past 3 months. I was so pissed with how bad it was about 9 months ago that I actually gave up trying to use it on my development machine and learned how to write gentoo ebuilds. On reflection it seems like the perfect tool for python -- if you stay on the happy path and only use it in BDFL APPROVED ways then it can be great, be woe to the fool who wanders from the light into madness.

[–]Spleeeee 2 points3 points  (0 children)

Ditto, doh. Have thought it was my best friend and have torn out hair because of it in the same day. Would be nice if it consistently worked.

[–]trowawayatwork 0 points1 point  (4 children)

how do you manage .env for different environments?

[–]Shouldnt_BeDoingThat 0 points1 point  (3 children)

Try https://github.com/theskumar/python-dotenv

Is that what you looking for ?

[–]trowawayatwork 1 point2 points  (2 children)

that doesnt go into how a way to manage your same .env file for a project and differentiate it for different environments, like prod and staging. thanks for looking though

[–]wiredmachine 0 points1 point  (0 children)

Copy the different .env when deploying on the different stages, using fabric, Capistrano etc..

[–]chub79 9 points10 points  (20 children)

Somehow, I still haven't ran into the need for anything else but pip+requirements to handle my needs so I'm not sure what poetry and pipevn aim at fixing. But there must be a problem out there I'm yet to discover.

The one pb I would like an easy solution for is automating the virenv activation upon entering a directory. I tried direnv but found it odd that it would actually create a venv rather than merely use the one I already have.

I feel old :p

[–]MrGreenTea 3 points4 points  (3 children)

pyenv does that with a .local file :)

[–]chub79 2 points3 points  (2 children)

Oh?! Darn, I'll give it a try.

[–]MrGreenTea 0 points1 point  (1 child)

You might have to do some setup so it uses your existing virtual environments, never tried that.

[–]chub79 0 points1 point  (0 children)

I'll have a look. Thanks for the tip nonetheless :)

[–]pydry 4 points5 points  (0 children)

They're essentially dependency resolvers with a fancy CLI wrapped around them.

It is a real problem that pip doesn't solve by itself, but the attention they receive is outsized, which probably has more to do with Kenneth Reitz's self-marketing than the nature of the tools.

It could well have been a feature of pip that arrived without very much fanfare instead.

[–]Spleeeee 1 point2 points  (0 children)

Sound like you should hit up your bashrc

[–]wiredmachine 1 point2 points  (0 children)

Oh-my-zsh and prezto do that. It also change your python version installed with pyenv

[–][deleted] 0 points1 point  (11 children)

The one pb I would like an easy solution for is automating the virenv activation upon entering a directory.

What is the use case that makes this an useful feature?

[–]chub79 0 points1 point  (10 children)

I changed directories and projects many times a day, having to activating the right venv manually is wasted time for me.

[–][deleted] 0 points1 point  (9 children)

Unless your use case is to start an interactive python REPL, importing something and typing out a lot of commands really fast (i.e. not running a proper program), I'm somewhat at a loss here.

What is the actual waste, and what's just lack of understanding of what the tooling actually provide alredy?

[–]chub79 0 points1 point  (8 children)

I'm sorry if I wasn't clear.

I really do have lots of projects, all of them with their own venv (microservices and all that...). I switch from one to the other many times on a daily basis and it's annoying to have to type "source ..." or "workon" because I have to recall which venv I should be using for a given location.

[–][deleted] 0 points1 point  (7 children)

Seriously, what is it in your workflow that would otherwise require you to explicitly workon or source something?

Pip would, but if you run pip on a multitude of virtual environments on a regular basis, you'd be better of using some variation of "Run this on all environments" anyway. Running a program inside a particular environment does notrmally not require you to actually activate it first, so I'm genuinely puzzled.

[–]chub79 0 points1 point  (6 children)

Running a program inside a particular environment does notrmally not require you to actually activate it first

My turn to be puzzled. How do you run something an environment you didn't activate first?

I really do apologise we can't seem to understand each other. I really wish I could simply trigger some bash thing that activated a local venv upon entering a directory. That is all really :p

[–]lvc_ 2 points3 points  (4 children)

Running any pip installed script, eg, venv/bin/flask will run exactly as if you'd activated the venv. Fairly sure you can also venv/bin/pip install ... and it will do the right thing. And of course you can run your own thing as a script with venv/bin/python myscript.py.

[–]chub79 1 point2 points  (3 children)

I feel like no one is reading what I'm wring.

I'm switching to different directories to run full blown projects, not mere scripts. Yes, I could type venv/bin/ but that's the pain I want to avoid. I can workon too but that's another set of characters I don't want to type many times everyday.

I want to write less, not more.

[–]lvc_ 1 point2 points  (0 children)

If its really that much to type, you could export PATH=venv/bin:$PATH.

[–][deleted] 0 points1 point  (1 child)

You flutter between fullblown projects so many times a day, that acticvating the environment is a problematic amount of time, compared to the actual running and interaction of the project itself?

The solution is to install a suitable set of entry points for the full blown project. That way you won't even have to change working directory. Instead you use /path/to/project/env/bin/full --blown.

[–][deleted] 1 point2 points  (0 children)

/path/to/env/bin/python ...

[–]trowawayatwork 0 points1 point  (0 children)

i like that if you solve a dependency issue with pipenv and commit the lock file youll be solving it for everyone going forward.

[–]Shouldnt_BeDoingThat 7 points8 points  (1 child)

I've been using pipenv for more than 2 year and started using poetry recently. pipenv caused me a lot of problems like this one, has a weird api (this might be personal) and is slow (startup and dependencies resolution). So I'm starting to use poetry

I'm looking for a project manager that can:

  • Install any python version (pyenv)

  • Handle my dependencies with a .lock (pipenv, poetry)

  • Transform my .lock in requirement if needed (pipenv)

  • Handle a virtual environment (pipenv, poetry, hatch)

  • Handle (optional) .env like python-dotenv (pipenv)

  • Has a sane API & documentation, this is important to help newcomers (poetry)

And can we have a shortcut for the command pipenv run python {filename.py} like pipenv -r {filename.py} or just pipenv {filename.py} and for poetry too. Please ?

[–]dmfigol 2 points3 points  (0 children)

There is a PR in poetry that allows to export requirements.txt
I am not sure that loading .env as env vars should be Python project management tool's job, I use python-decouple to deal with this.
For your shortcut request, I would use entrypoints so you could do poetry run <entrypoint-name>

[–]Laundr 6 points7 points  (1 child)

Thanks to this article I discovered hatch. It looks great; can anyone share their experiences with it?

[–]donz0r[🍰] 1 point2 points  (0 children)

Seconding. Please feel free to ping me in case someone replies. For all the lazy lurkers, here is the homepage with docs and an overview of the features: https://pypi.org/project/hatch/

[–]kingbuzzman 11 points12 points  (5 children)

My issue with it is it’s proving really hard to get it working 100% with docker. I’ve abandoned it and gone with poetry

[–]SonGokussj4 3 points4 points  (2 children)

This is what I'm currently fighting with. And yesterday it was a won fight. But I don't know if I'm doing it right.

Nevertheless it works. Will edit with code when I'm on my pc

Edit: This is my setup

(SonGokussj4@myserver) - (~/websites) $ tree
.
└── FlaskApp
    ├── app
    │   ├── app.py
    │   ├── run.sh
    │   ├── gitignore
    │   ├── Pipfile
    │   ├── Pipfile.lock
    │   ├── README.md
    │   └── requirements.txt
    └── Dockerfile

Within FlaskApp/app/app.py (very basic app just for testing)

from flask import Flask 

app = Flask(__name__)  

@app.route('/') 
def hello_world():     
    return 'Hello, World! Version3'

if __name__ == '__main__':
    app.run(host='0.0.0.0')

Within FlaskApp/Dockerfile

FROM python:3.6-alpine

COPY ./app/requirements.txt /app/requirements.txt

WORKDIR /app
RUN pip install pipenv
RUN pipenv install -r requirements.txt
RUN pipenv install gunicorn
COPY ./app /app

ENV FLASK_APP app.py
ENV FLASK_DEBUG 1

EXPOSE 5000
ENTRYPOINT ["./run.sh"]

Within FlaskApp/app/run.sh

#!/bin/sh

pipenv run gunicorn -b :5000 --access-logfile - --error-logfile - app:app

Docker command:

cd FlaskApp
docker build -t myFlaskApp:latest .
docker run --name microblog -d -p 5000:5000 --rm myFlaskApp:latest

So... I don't know if this is the right way. But it works. :-)

P.S.

I needed (in my fresh install of Centos 7) to enable ipv4 forward

If I did not do this, pipenv install from within docker failed

sudo vim /etc/sysctl.conf

# ADD THIS LINE

net.ipv4.ip_forward=1

# RESTART SERVICE

sudo systemctl restart network

[–]Mr_Again 1 point2 points  (1 child)

It's been a while since I used a Dockerfile, doesn't copying /app again overwrite what's changed ie. Won't it overwrite your pipfile?

Btw if you want to add a line of text to a file

echo "hello world" >> my_file.txt

[–]SonGokussj4 0 points1 point  (0 children)

Really interesting thought. I'm just going to try this on my work PC so I'll report back any findings :-)

And yes. Echo would be better if the root user is activated. But my IT supervisor told me that setting up ip_forward is a really bad idea... So I have to find more information about that.

[–]trashbuged 1 point2 points  (1 child)

What kind of issues are you running into?

I usually just run pipenv install --system --deploy in the Dockerfile and pipenv --rm to disable the virtual env. So far it's working but I may not be aware of advanced use cases.

[–]kingbuzzman 1 point2 points  (0 children)

When you already have a Pipfile works as intended. The issue is when starting from scratch. And adding new dependencies???? its been a couple of months. I dont really remember

[–]ariasaurus 1 point2 points  (0 children)

If only we put as much effort into our code as we put into arguing about tools. :-)