Hacker News new | ask | show | jobs
by michaelmcmillan 2887 days ago
Never had a problem with dependencies in Python. Just keep it simple.

When starting a new project:

  virtualenv venv -p *path-to-python-version-you-want*
  ./venv/bin/pip install *name-of-package*
When running that project:

  ./venv/bin/python *name-of-python-file*
Many people don't realize that the venv/bin/ contains all the relevant binaries with the right library path's out of the box.
2 comments

Pipenv is a good replacement for the above workflow. It manages your dependencies and virtualenvs.
Thanks for the tip, but honestly, I don't need another tool.
I was of the same mentality, until yesterday when I watched this PyCon video, uploaded 13 May 2018.

https://www.youtube.com/watch?v=GBQAKldqgZs

To cut a long story short, if you're happy with virtualenv and pip then that's great, but the idea of pipenv is to replace virtualenv and pip, which means you'll actually have one tool fewer. :)

Genuine question: does pipenv do anything that [mini]conda doesn't?
Everything you need to know about pipenv is in the linked talk. Sorry, I don't know anything about [mini]conda.
Does conda create a lockfile?
Not yet. But that's planned. See See https://github.com/conda/conda/issues/7248.
Is there a reason you don't "activate" your virtualenv?

That (with the addition of using mkvirtualenv and friends) is the workflow I use to both dev and prod and am really happy with!

I hate the whole idea of activating virtualenvs. It's a tool that makes it really easy to end up running a command in the wrong environment and see weird behavior instead of a clear error message.

I've seen variations on this scenario happen at least 3 times, for instance:

1) Somebody creates script that activates and runs django and commits it.

2) Junior runs script but the virtualenv doesn't get created for some reason.

3) The "warning virtualenv doesn't exist" message appears briefly and gets missed.

4) The junior gets "import error: cannot import django" or something.

5) They then start installing django in their system environment and... it sort of works. Except then they get another import error. And a whole bunch of python packages installed in their system environment. Yech.

Moreover, I'm really not sure what was so wrong with just running ./venv/bin/python in the first place and never having to worry about what environment you're in.

> 1) Somebody creates script that activates and runs django and commits it.

You can call the python bin inside the virtualenv and it will run as if the virtualenv was active:

  venv/bin/python -m foo.bar
Obviously it doesn't work if devs used different names for their virtualenvs. Work has a convention to always use the same name so this works pretty well.
That's 7 characters more you'll need to write all the time! Also you'll need to remember to prepend them to all scrips, ie pip, fab etc. Well that seems to me to be more error prone for juniors than telling them to always use a virtual env (ie have (envnane) in their prompt)!!
It's less error prone. Never had ^^ that scenario since and I've not run into additional problems either.

Having an extra 7 characters in a ./run.sh script doesn't really bother me. I'm not a perl developer.

I don't like "magic". I don't need anything to hijack PS1 and muck around with my shell.
I heartily agree with this. I really dislike the tools that provide their functionality by mucking around with the shell environment in (essentially random after accounting for platform variations) ways ...

Tools like nvm, rvm, ros ... If I can use a solution for managing a development context that doesn't involve mucking around with the shell environment I much prefer it. Configuration via the sourcing of shell scripts is a very fragile interface, doesn't work when with good (ie non-bash) shell, and almost always eventually leads to bugs when some workflow triggers processes in a manner that fails to inherit the shell environment...

Fair enough.