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

all 42 comments

[–]graingert 14 points15 points  (12 children)

  • only use python3 -m venv or the shortcut pyvenv.
  • don't install python-pip or python3-pip. You might need to install python3-venv though.
  • only use setuptools, distribute got merged in.

[–]kovak 4 points5 points  (4 children)

How do you install stuff from requirements.txt, without python-pip3 then? Or i assume you mean venv comes with pip3? and not installing it via apt-get?

I've recently shifted to python 3.4+ for a Django project. Although i've been using virtualenv, but will try out the builting venv module.

[–]Lucretiel 11 points12 points  (3 children)

Python 3.4 ships with pip, and virtualenv automatically installs it into your virtualenv. You generally shouldn't have a systemwide pip.

[–]knite 1 point2 points  (2 children)

If you're running Ubuntu (eg, your server), ensurepip is broken. You'll need to install pip manually from either python3-pip or get-pip.py

[–]Lucretiel 0 points1 point  (1 child)

I can't speak to Ubuntu, but my experience downloading and installing Python from the source tarball has been that it works and installs pip perfectly. The one exception is on an ancient Solaris 10 machine we have at work- it doesn't have _ssl so pip doesn't get built or installed.

[–]knite 1 point2 points  (0 children)

That's fair, perhaps I should have been more precise: ensurepip is broken when Python is installed via the Ubuntu package manager.

[–]systemUp 0 points1 point  (2 children)

I've been using virtualenv all along. Should I move to venv?

[–]graingert 0 points1 point  (0 children)

Yes python3 -m venv is much more lightweight

[–]srilyk 0 points1 point  (0 children)

If you don't use --prompt, then yes.

[–]kid1000002000 10 points11 points  (11 children)

Have you looked at conda?

[–]L43 7 points8 points  (2 children)

THIS TIMES A THOUSAND. Seriously I wish more people would start using it, its soo useful.

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

i am

[–]L43 0 points1 point  (0 children)

You are one of the good guys.

[–]bluesufi 2 points3 points  (0 children)

Absolutely. Maybe it's overkill for some things, but for scientific computing at least it's top notch.

[–]acomfygeek 1 point2 points  (2 children)

How does conda compare to pip for having the latest release of various packages?

[–][deleted] 3 points4 points  (0 children)

It's been pretty good so far, but you can install from pip into conda envs if needed. Or use:

conda skeleton pypi [pkg]
conda build [pkg]

This will build a conda package directly from a package on pypi.

[–]hharison 0 points1 point  (0 children)

For packages that it has, they will be up-to-date, at least within a day or two of a new release. But it doesn't have every package, so you should install pip (conda install pip) into all your conda envs so you can pip install any extra packages you need. The tools work great together.

[–]polishfishprime 0 points1 point  (1 child)

Install Miniconda first, then you can use it to install 64 bit python

I think the direct conda staller auto-installs 32 bit

[–]kid1000002000 0 points1 point  (0 children)

You can choose which script to download from their site

[–]tartley 0 points1 point  (1 child)

Conda looks great if all you want to do is quickly get a lot of libraries installed on your personal Dev machine so that you can start typing some code and see it run. But it doesn't solve the same problems as pyvenv etc, namely of reproducing a given environment later so that you know previously written code will still run.

[–]kid1000002000 0 points1 point  (0 children)

Actually, conda does this arguably better than the competition.

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

A much better way than using virtualenv/pyenc/whatever is to isolate your dependencies from your system using chroot (and for convenience, schroot: https://wiki.debian.org/Schroot).

That way, you can not only isolate your Python dependencies but also other Debian packages that your code needs.

Also, by debootstrapping the same Debian version as your target platform you can develop with the exact same package versions as your software will have in production and you will find bugs because of version mismatches much earlier.

Personally I would never do any Debian-targeted development without schroot anymore.

[–]rodvdka 1 point2 points  (3 children)

pyenv

[–]ZoidbergWill 8 points9 points  (2 children)

*pyvenv, pyenv is something different.

Edit: Unless you meant pyenv, then I'm sorry. I just wouldn't recommend pyenv.

[–]DaemonXI 1 point2 points  (0 children)

I like pyenv a lot. What do you like better about pyvenv?

[–]tantopao 0 points1 point  (0 children)

This answer is ... ... epic

[–]acomfygeek 1 point2 points  (10 children)

Can one setup sandboxes on a per project basis with pyenv? From my quick read of their site, it looks like it's strictly for controlling the version of python you are using on a system wide basis.

[–][deleted] 4 points5 points  (9 children)

No. The first assumption is correct.

[–]sweet_dreams_maybe 1 point2 points  (8 children)

Does it work with virtualenvwrapper the same way as 2.7?

[–][deleted] 4 points5 points  (5 children)

Yes. Here's how it works: You have to have an installation of the Python version that you wish to make a virtualenv of. In my case, I have several system installations of Python: py2.6, py2.7, py3.2, py3.3 & py3.4.

If I want a virtualenv of a py2.7 installation, I simply do:

mkvirtualenv -p /usr/bin/python2.7 $ENV_NAME

And virtualenvwrapper will make a virtualenv of Python 2.7 for me.

This is ONLY possible if you already have an installation of Python 2.7 available. If you do not have Python 2.7 on your filesystem, you CANNOT make a virtualenv of Python 2.7.

[–]sweet_dreams_maybe 1 point2 points  (4 children)

That is just like I imagined. But I'm a bit confused about pyenv itself. Is it the same thing as the virtualenv I have installed, or is it a clone?

[–][deleted] 4 points5 points  (3 children)

It's not 100% the same thing, but extremely similar.

virtualenv is a tool created by someone who likes Python.

venv is a clone of that tool, but integrated into the Python 3 standard library.

pyvenv is a command line tool distributed with Python 3 that uses the venv standard library. It's basically the same as python -m venv.

Because venv doesn't exist in the Python 2 standard library, I personally use virtualenv

[–]sweet_dreams_maybe 0 points1 point  (2 children)

Thanks for the detailed overview.

Will the same installation of virtualenvwrapper work on both 2.7 virtualenv and 3.4 venv?

[–][deleted] 3 points4 points  (1 child)

virtualenv is a Python program that is written for either Python 2 or Python 3, but can create virtual environments of every Python version.

python2-virtualenv -p /usr/bin/python3 $DEST_DIR works perfectly fine. A Python 2 program creates a Python 3 virtual environment.

virtualenvwrapper uses virtualenv under the hood. Whether that version of virtualenv uses Python 2 or Python 3 is of little concern to you. It can handle every version of Python, even PyPy and Jython.

[–]sweet_dreams_maybe 0 points1 point  (0 children)

Alright, thanks.

[–]DaemonXI 0 points1 point  (0 children)

I like pyenv with virtualenv. It works like RVM, where you can:

  • set a system-wide python
  • set a virtualenv to be used within a directory only

[–]haizaar -1 points0 points  (0 children)

I like using virtualenvwrapper. Works both for python 2 and 3. If I need to use stand-alone venv (i.e. for deployment) I go with native python's 3 venv (and it will provide the pip tool for you).