Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
bitprophet
Jul 22, 2004
Taco Defender
Totally coming to PyCon next year, have the talks list open but haven't read it yet :v: but excited already!

nbv4, you want to use pip, e.g. pip install -e git://github.com/username/projectname or pip install -e git+ssh://server:repo.git or whatever. king_kilr is pretty handy with it I hear.

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns

bitprophet posted:

Totally coming to PyCon next year, have the talks list open but haven't read it yet :v: but excited already!

nbv4, you want to use pip, e.g. pip install -e git://github.com/username/projectname or pip install -e git+ssh://server:repo.git or whatever. king_kilr is pretty handy with it I hear.

OK I see now. The repo I want to install is here: http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk

when I do this:

code:
pip install -e bzr+http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk#egg=django_openid_auth
it returns this:

code:
zsh: no matches found: bzr+http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk#egg=django_openid_auth
but if I do this:

code:
bzr branch http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk
it works fine......

nbv4 fucked around with this message at 20:20 on Nov 5, 2009

ATLbeer
Sep 26, 2004
Über nerd

nbv4 posted:

virtualenv nub here. Whats the recommend way to install a module from svn or git or something? Do you just navigate to the /site-packages/ directory within the virtualenv then do a checkout?

Just get into the virtualenv (source/bin activate) then just run setup.py like normal or like you said... just drop it in site-packages

Pretend like it's the normal site-packages directory

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Avenging Dentist posted:

Ok design question: I have several related C interfaces which may or may not be present in a given implementation. The interfaces look like: :words:

Incidentally, the solution to this is a la namedtuple.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

nbv4 posted:

OK I see now. The repo I want to install is here: http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk

when I do this:

code:
pip install -e bzr+[url]http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk#egg=django_openid_auth[/url]
it returns this:

code:
zsh: no matches found: bzr+[url]http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk#egg=django_openid_auth[/url]
but if I do this:

code:
bzr branch [url]http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk[/url]
it works fine......

You're getting a zsh error caused by the # in the url. Try putting the url in quotes, or escaping the #, or something like that.

tripwire
Nov 19, 2004

        ghost flow
Is there any way to "freeze" a python application such that it could be used on osx, from Windows? I've used py2exe before for making exe's and it worked perfectly, but if I want to be able to give someone on a mac a single file they can run without having to install any python libraries, would I need to do that from a unix based system? I don't have any c compiler available on windows at the moment if that makes any difference.

ATLbeer
Sep 26, 2004
Über nerd

tripwire posted:

Is there any way to "freeze" a python application such that it could be used on osx, from Windows? I've used py2exe before for making exe's and it worked perfectly, but if I want to be able to give someone on a mac a single file they can run without having to install any python libraries, would I need to do that from a unix based system? I don't have any c compiler available on windows at the moment if that makes any difference.

py2app

tripwire
Nov 19, 2004

        ghost flow

ATLbeer posted:

py2app

Thanks!

tripwire
Nov 19, 2004

        ghost flow
On a related note, does anyone have any idea what to do if py2app fails with

KeyError: "There is no item named 'pkg_resources.pyc\\\\' in the archive"

Kind of scratching my head here.

I can see the file sitting in my C:\python26\Lib\site-packages\ directory. is it breaking because of all those extra backslashes in there? Anyone seen something like this before?

tripwire fucked around with this message at 17:22 on Nov 6, 2009

tripwire
Nov 19, 2004

        ghost flow
Am I retarded or does py2app simply not work from windows?

Maybe it was stupid but I dug right in that son of a bitch and made it strip trailing backslashes from files it was trying to grab.
Then it tripped up trying to make a symlink, which it obviously cannot do if its not a posix platform.

Lurchington
Jan 2, 2003

Forums Dragoon

tripwire posted:

Am I retarded or does py2app simply not work from windows?

Maybe it was stupid but I dug right in that son of a bitch and made it strip trailing backslashes from files it was trying to grab.
Then it tripped up trying to make a symlink, which it obviously cannot do if its not a posix platform.

py2app is supposed to be run from a mac, some googling suggest things like VMWare to get a Mac environment, but that might be just as ornery.


edit: I'm going to just vent here, but after playing with collections.MutableMap and anydbm, I spent 2 hours trying to figure out why my data wasn't persisting. I thing realized that I was setting my item as
pre:
obj[value] = key
and testing:
pre:
key in obj
:mad:

Lurchington fucked around with this message at 18:07 on Nov 6, 2009

tripwire
Nov 19, 2004

        ghost flow
time to boot into linux

Only registered members can see post attachments!

nbv4
Aug 21, 2002

by Duchess Gummybuns
My project uses django, PIL, matplotlib, Basemap, numpy, and a few others, as well as a number of django specefic apps. Should I be putting all of those into my virtualenv, or should I be installing the bigger ones such as PIL and matplotlib into dist-packages? Or is that defeating the whole point of virtualenv?

Sailor_Spoon posted:

You're getting a zsh error caused by the # in the url. Try putting the url in quotes, or escaping the #, or something like that.

actually i just removed everything beyond the "#" and it seemed to work v:shobon:v

king_kilr
May 25, 2007

nbv4 posted:

My project uses django, PIL, matplotlib, Basemap, numpy, and a few others, as well as a number of django specefic apps. Should I be putting all of those into my virtualenv, or should I be installing the bigger ones such as PIL and matplotlib into dist-packages? Or is that defeating the whole point of virtualenv?


actually i just removed everything beyond the "#" and it seemed to work v:shobon:v

Some people put super global, fixed version, things in their global site packages (like psycopg, PIL, numpy, etc.). Personally I keep everything in my virtualenv, and I use the --no-site-packages option when I create my venvs.

ATLbeer
Sep 26, 2004
Über nerd

tripwire posted:

Is there any way to "freeze" a python application such that it could be used on osx, from Windows? I've used py2exe before for making exe's and it worked perfectly, but if I want to be able to give someone on a mac a single file they can run without having to install any python libraries, would I need to do that from a unix based system? I don't have any c compiler available on windows at the moment if that makes any difference.

Opps.. Sorry, I read your post way too fast.

As far as I know, you won't be able to compile something to run on a Mac without using a Mac itself.

Sorry about leading you down the py2app path by accident there.

Kire
Aug 25, 2006
On the subject of free books and printable online docs, I've checked the OP and printed out several binders of free books, but are there any other recommendations?

My office has a bindery that I use after hours so I can print stuff and organize it really well. I'd love some more books to add to my nerd library, or just helpful things to print out and have posted in my office.

Lurchington
Jan 2, 2003

Forums Dragoon
Docs for GUI frameworks could be useful for you. Maybe something like: http://www.wxpython.org/onlinedocs.php

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


I'm trying to write a handler using mod_python that will process all requests on a specific directory and perform some action before serving the originally requested file. Is this possible? I'm really only familiar with the mod_python publisher which is a completely different animal.

aSSbAG.
Apr 10, 2005

Somethingawful's MAD Trucker
Hey guys, just decided to learn python. I used to consider myself a pretty good VB6 programmer, and was waiting for microsoft to realize what a huge mistake they made with VB.net, yeah I got tired of burning that torch.

I downloaded and installed the latest version from python.org and since then I have been doing some reading, haven't gotten any further then "hello world" but that's fine by me, I'm in no big hurry. I then find this thread which led me to pyglet which sounds bad as hell. So I download it and try to install:




3.1 < 2.4? :ughh:

Yeah I'm gonna love python :(

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


aSSbAG. posted:

Hey guys, just decided to learn python. I used to consider myself a pretty good VB6 programmer, and was waiting for microsoft to realize what a huge mistake they made with VB.net, yeah I got tired of burning that torch.

I downloaded and installed the latest version from python.org and since then I have been doing some reading, haven't gotten any further then "hello world" but that's fine by me, I'm in no big hurry. I then find this thread which led me to pyglet which sounds bad as hell. So I download it and try to install:




3.1 < 2.4? :ughh:

Yeah I'm gonna love python :(

Python 3.0 is a huge departure from 2.x and as such many libraries need to be updated to do things the new way. You need to either get the latest 2.x release or wait until Pyglet supports 3.x. I'm not sure why that information isn;t front and center on the Pyglet website. But yeah, that's a pretty terrible message that doesn't describe the actual problem.

aSSbAG.
Apr 10, 2005

Somethingawful's MAD Trucker
Should I just keep going with 3.x and wait for everything else to catch up then? I don't see the point of learning something that's already on the way out.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

aSSbAG. posted:

Should I just keep going with 3.x and wait for everything else to catch up then? I don't see the point of learning something that's already on the way out.

There's very little real difference on the surface, and most code is convertible with a simple tool. Stick to 2.x for now - you'll have a much better time - but be aware of what's changing.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

aSSbAG. posted:

Hey guys, just decided to learn python. I used to consider myself a pretty good VB6 programmer, and was waiting for microsoft to realize what a huge mistake they made with VB.net, yeah I got tired of burning that torch.

The only mistake with VB.NET was that they used VB6 as a basis.

Also I really question the notion that Py3k is a "huge departure" from Python 2.x. There are some important differences, but it's still more-or-less the same syntax, and the number of stuff that changed (as opposed to being added) could probably be summed up in a page.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


Avenging Dentist posted:

Also I really question the notion that Py3k is a "huge departure" from Python 2.x. There are some important differences, but it's still more-or-less the same syntax, and the number of stuff that changed (as opposed to being added) could probably be summed up in a page.

Probably. I'm still developing for 2.3 so for me it feels much bigger than for everyone else.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Avenging Dentist posted:

The only mistake with VB.NET was that they used VB6 as a basis.

Also I really question the notion that Py3k is a "huge departure" from Python 2.x. There are some important differences, but it's still more-or-less the same syntax, and the number of stuff that changed (as opposed to being added) could probably be summed up in a page.

Sure, it's not (on my opinion) a "huge departure". However, I think the developer is still in the position of deciding whether they code for 2.x or 3.0, rather than "2.x or higher". And - for anyone but language wonks - the best advice is to program for 2.x for the meanwhile.

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

HatfulOfHollow posted:

I'm trying to write a handler using mod_python that will process all requests on a specific directory and perform some action before serving the originally requested file. Is this possible? I'm really only familiar with the mod_python publisher which is a completely different animal.

Yes, it's incredibly trivial. SetHandler in a <Directory> block and return apache.DECLINED from the handler.

Even better, don't use mod_python at all.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

outlier posted:

Sure, it's not (on my opinion) a "huge departure". However, I think the developer is still in the position of deciding whether they code for 2.x or 3.0, rather than "2.x or higher". And - for anyone but language wonks - the best advice is to program for 2.x for the meanwhile.

Agreed on both counts - 3.x feels pretty much the same-old-same-old to me, but there's enough minor differences that a module probably has to be developed for 2.x or 3.x. To those who are just learning Python - 2.x is the way for the moment, and when the time comes 3.x won't be that big a change.

ErIog
Jul 11, 2001

:nsacloud:
I think people are confused about the way a project like Python works. The 2.x and 3.x distinction is really about compatibility. The idea is that within a major version number, your code should be forward compatible, and in some cases backwards compatible depending on if you're using new features. All that number really means is that if you write something on 2.3, it will continue to work for 2.3 through 2.x.

So the introduction of Python 3 is mostly sending a signal about compatibility. They are breaking the forwards compatibility thing because of a few features they feel are necessary. These don't have to be giant sweeping changes. They can be small changes to the way Python works that end up breaking compatibility.

It's not really a lot of work to transition code from 2.x -> 3, but the change in major version number is a signal that you can't just run 2.x code straight in 3.x.

Just because version 3 exists doesn't mean you have to use it, and in most cases, it's recommended that you not use it for apps you'd like to easily distribute until it becomes commonly pre-installed like 2.x is. That said, I still think the most commonly installed version of Python in the ecosystem is 2.3 or 2.4 even though there exist versions after them. These things can take a bit of time to work their way into distros.

The way the system is now with the introduction of 3 while 2.x is still entrenched is a pretty decent way of handling compatibility issues while still pushing forward with development of the language. It also means that programmers have a very reasonable amount of time to transition their code.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Thought I'd post this here as esr wrote ForgePlucker in python. He's had a couple blog posts about the wisdom of scraping HTML with regex, and as always, the posts and the comments are entertaining.

http://esr.ibiblio.org/?p=1411

tef
May 30, 2004

-> some l-system crap ->

Thermopyle posted:

Thought I'd post this here as esr wrote ForgePlucker in python. He's had a couple blog posts about the wisdom of scraping HTML with regex, and as always, the posts and the comments are entertaining.

http://esr.ibiblio.org/?p=1411

He's talking out his arse as normal. Also, real men use lxml to scrape webpages. The comments are simply more noise.

On the other hand this is a comparatively more useful and informative post about scraping:

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

tef fucked around with this message at 19:16 on Nov 17, 2009

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ErIog posted:

I think people are confused about the way a project like Python works. :words:

This is what everyone else already said, only with fewer words.

king_kilr
May 25, 2007

tef posted:

He's talking out his arse as normal. Also, real men use lxml to scrape webpages. The comments are simply more noise.

On the other hand this is a comparatively more useful and informative post about scraping:

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

People with poo poo to do use PyQuery, beautiful API, fast as hell (it's built on lxml), I can't say enough good about it, if you are parsing HTML any other way you are an idiot.

tef
May 30, 2004

-> some l-system crap ->

king_kilr posted:

People with poo poo to do use PyQuery, beautiful API, fast as hell (it's built on lxml), I can't say enough good about it, if you are parsing HTML any other way you are an idiot.

(We had an existing team that knew how to use xpath over css selectors. xpath is pretty awesome)

king_kilr
May 25, 2007

tef posted:

(We had an existing team that knew how to use xpath over css selectors. xpath is pretty awesome)

I'll take your word for it :) I build websites so we all know CSS selectors.

ErIog
Jul 11, 2001

:nsacloud:

Avenging Dentist posted:

This is what everyone else already said, only with fewer words.

I realize. It was just that I got a vibe from people saying it wasn't a "huge departure," like that was news that there was somehow a lot of people who thought it was supposed to be.

VirtuaSpy
Jul 26, 2002

OMG WTF FIREEEE!!
So I've been using Python for a couple of years now for my graduate research, for data reduction and plotting and whatnot. I'm currently using the Spyder IDE as another goon referred me to the project, and I'm very happy with it as a MATLAB replacement for many reasons. I even got the chance to talk to one of the high up MATLAB developers as to why I prefer the Python setup versus a commercial package like MATLAB. I'm currently using python + numpy + scipy + matplotlib with it happily thus far.

I've also tried the Sage implementation, which includes the above mentioned packages and then some others related to numerical computing. The notebook browser interface is handy, but I find myself sticking to the text editor or Spyder approach so far. I know Sage includes other packages useful for numerical and math work, but are there any math/Python/science folks that can chime in on if I should consider using Sage full time versus the setup I have now?

I realize that it's all about personal preference and all, but I just don't see a reason to use a packaged setup like Sage for now. Any insight is appreciated, and in the end, it's really a big pleasure to use either setup over MATLAB for many reasons.

wins32767
Mar 16, 2007

sonic bed head posted:

I just downloaded pydev for eclipse and I am having a lot of trouble figuring out why I get unresolved imports when the code runs without errors. The code that I'm working with is very basic and the problem still happens.

After I got an unresolved import for logging (the standard library module), I just turned them off.

Go to Window->Preferences->PyDev->Editor->Code Analysis and open up the imports tab. Change Import not found from Error to Ignore.

nbv4 posted:

virtualenv nub here. Whats the recommend way to install a module from svn or git or something? Do you just navigate to the /site-packages/ directory within the virtualenv then do a checkout?

Packages should have a setup.py file in the root, if so, use that to install (or make an egg and then install that).

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

What's the right way to debug a function?

Specifically, I'm working on a script right now with a function that's giving me some problems. When it drops back to the interactive interpreter I'd like to explore the values of various variables that are local to the function, but we're not in the function anymore so those variables aren't accessible.

code:
def somefunc(wiggedywhack):
	stupid = []
	for i in range(10):
		awesome_broken_code
		stupid.append(i)

somefunc('cawk')

#awesome_broken_code breaks, how do I inspect 'stupid'

Lurchington
Jan 2, 2003

Forums Dragoon
well, I usually stick a few printouts (or logger calls) inside of the function and take a look at the change over time.

Your code is intentionally pretty vague so that's all I could say. Maybe you stick in a few assert statements if you want to ensure a particularly bad result isn't happening.

Adbot
ADBOT LOVES YOU

CoderCat
May 7, 2005

Science, it works. :science:

Thermopyle posted:

What's the right way to debug a function?

Add the following where you want the debugger to kick in:
code:
import pdb; pdb.set_trace()
Run your script. When it reaches that line, the debugger starts. You can inspect variables using:
code:
pp stupid
To continue executing the code, use the 'c' command. For more help on commands, use the 'h' command.

  • Locked thread