Python Development on Linux and Why You Should Too
thelinuxexperiment.com
thelinuxexperiment.com
Basically, you should never ever find yourself typing sudo pip. If you refuse to use a virtualenv for some reason, use pip --user.
The other benefit of this approach is that your system package manager will keep your system packages up to date and the required versions for any software on your system.
Honestly, I think the best solution in the long term would be for pip, by default, to install to a user environment (installing in ~/.local using the --user flag) if it is run unprivileged and not in a virtualenv.
- Never run pip outside of a virtualenv. I prefer to use virtualenv directly so that I have everything contained in my working directory, but virtualenvwrapper is fine too.
- Never install system-wide Python packages directly. Okay, I'm exaggerating, but I don't think I've ever needed a system-wide Python package as anything more than a dependency - and in the rare case when I have, the AUR (in my case) makes it easy to wrap a setup.py file inside a 'system' package.
The only problem with this workflow is that I still haven't figured out how to change the IPython module path, so when I run IPython inside a working directory with a virtualenv activated, I access the system packages, not the locally-installed ones. I could pip install IPython, but that'd add a completely unnecessary dependency to every project. Does anybody know an easy way to switch the path for IPython via command line switch, etc.?
My major problem I have is packages using cython or depending on external C header files in some other way. For example, matplotlib and the IPython qtconsole.
For one, I don't even have gcc on servers that I want to deploy to using a virtualenv. but the major pain is finding out what *-dev packages I need to have installed in order to install using pip (if it can be done at all).
I don't think I ever had the IPython qtconsole working from a virtualenv without using system site packages.
Two things:
1. Fedora and related distribution users will want to say "yum -y install python" instead.
2. But it's hard to imagine a distribution that doesn't have Python installed by default, because so many Linux system utilities are written in Python.
Another quote: "Alternatively, you can just start hacking away and use StackOverflow to fill in any of the gaps in your knowledge."
Yes, good suggestion, but there's always the searchable online Python documentation:
And if you're offline for any amount of time, the documentation can be downloaded:
http://docs.python.org/download.html (2.x)
http://docs.python.org/py3k/download.html (3.x)
Python has some amazing libraries -- even symbolic algebra (what Mathematica does):
from sympy import *
x,a,b,c = var('x a b c')
pprint(solve(a * x**2 + b * x + c,x), use_unicode=False)
The result: _____________ / _____________\
/ 2 | / 2 |
-b + \/ -4*a*c + b -\b + \/ -4*a*c + b /
[---------------------, -----------------------]
2*a 2*a
The Unicode output is, of course, much nicer: ⎡ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ⎛ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎞⎤
⎢ ╱ 2 ⎜ ╱ 2 ⎟⎥
⎢-b + ╲╱ -4⋅a⋅c + b -⎝b + ╲╱ -4⋅a⋅c + b ⎠⎥
⎢─────────────────────, ───────────────────────⎥
⎣ 2⋅a 2⋅a ⎦To enable that, run:
%load_ext sympyprintingSomething I've wanted to do for a very long time is pick up Linux and to be able to use it as well as your typical developer that uses Linux from day-to-day. For this reason, I've decided to pick up Python and use it on my new Ubuntu desktop (dual-boot on top of Windows 7) along with the online version of Learn Python the hard way.
So far, it's been a real struggle to get things working the way I'd like. Writing Python on Windows 7 has been a surprisingly painless experience so far, but getting something like Django set up took me hours. Perhaps I just suck with Linux, who knows?
Outside of the pain of setting things up things just seem to work well and I'm glad that I decided to take the plunge in Linux over Windows. Python might not ever pay the bills, but I can apply myself in a different way and perhaps make myself employable in the future outside of .NET or Java. I love "The Unix Way" of doing things and hopefully it'll eventually click.
I suggest you just jump right into it. Being well versed in Linux doesn't mean you will not hit walls. You will. I guarantee it. It just means you will understand why did you hit the wall and how to jump over it. I suggest you create a VM with Ubuntu running on it and just install stuff without a fear of breaking it. One of the most fun (and frustrating) experiences I had was with learning how to use chmod. I once changed almost every file on the OS to file settings 777 (writeable, readable by anyone).
Just keep hacking at it. It has taken me at least 6 years to reach this point.
I'm a little surprised that the grandparent post had trouble setting up Django, though. Once you've installed the python-django package, you should be able to follow the Django tutorial straight away.
This comes off to me as a major disconnect. It almost looks like you're saying making a script to automate a setup is as easy as a point-and-click interface. I would say setting up the script is less convenient, in that you need to learn basic shell scripting first. Point and click requires you to learn basically nothing. Using a CLI rather than a mouse requires worlds more brain power and is worlds less intuitive when you're coming from a Windows world.
Writing scripts is a medium-long term investment. You're right that for one off tasks it's quicker to point and click, but once you need to repeat that task, scripts are faster.
A case in point: I was setting up automated tests on a Windows machine today, and I had to install pywin32 automatically in a virtualenv. Both the download page and the installer are built for a human to click through, and are problematic to do from a script.
That's a Django thing; I remember its setup/configuration to be a bit wonky compared to most Python packages.
Just learn how to use virtualenv + pip, and that's most of the setup you should need for Python development on Ubuntu. The added plus about using virtualenv from the start (I don't think it was around when I was learning Python) is that you get a very clear understanding of what the project structure and dependencies are... it took me a while to figure that out when I first started.
Also:
> Perhaps I just suck with Linux, who knows?
Nah, that's just the process of migrating for the first time from a completely different OS. You'll get the hang of it the more you use it.
Basic things: apache, nginx, supervisord - underpowered or completely missing. Ipython is my favorite shell in Windows, but in Linux it works better (just because console is better in Linux).
Have you tried to run Django under IIS? I assure you - it's pain.