PyCon 2014

Creando fácilmente paquetes para Python

Asheesh Laroia  · 




Extracto de la transcripción automática del vídeo realizada por YouTube.

welcome everyone to Python packaging simplified by a shoosh Laura hi everyone Wow hi everyone hi great so I'm here to talk about Python packaging simplified and as this title slide suggests I'll provide information useful to end users app developers

open source contributors this talk is focused mostly on people who aren't the one packaging things there will be tough talk after this in more depth I can talk about that at the end also there's also a couple of micro changes that you mostly don't

care about sometimes in the in the in the description I promised that I would tell you how to debug complicated conflicts between Debian installed packages and piff installed packages if people really want to know that you can ask me the questions there wasn't

time to fit it to fit it in and do it justice so with that said I will explain to you the goals of this talk I want everyone who attends this talk to be able to install Python code on their own system without needing to use root privileges or admin privileges

or sudo I also you to want to have a basic understanding of how to distribute Python code that you've written and then I also want you to know how to learn more because there isn't time to do justice to everything in Python packaging land so it's

helpful if you know the basics and what are the right questions to ask and then you can do the right research to find out the answers so let's talk about installing Python code if you have a Python interpreter it might look something like this and if you're

lucky your Python interpreter comes with batteries included one of those modules is the numbers module anyone in here imported the numbers module ever yeah I just found the name of it in the Python standard library it sounded cool so when you import it anyway

it gives you a thing you can print and if you print the numbers module like any module it'll print the path that it came from this is one of the most important things to know about Python packaging that the module object will tell you where it came from

if you let it tell you this can be super useful in debugging and it's driven by a list of directories that are searched when you import and that list is an assist module sistar path it's a list it looks something like this this is kind of long but

the numbers module definitely came from one of these entries and the purpose again that's to stop path is so that you can so the Python interpreter will search in each of these places for a module or something it can import until it satisfies your request

so I'll highlight second one here this path usual lib Python 2.7 is in fact where the numbers module came from so that's great if you want to use Python code that comes in the standard library but you might want to install things that aren't in

a standard library for example if it's around the time of Hurricane sandy and you've been reading this website regret see you might know that these cookies are a hurricane sandy special that you might want to buy they're handmade available for

you on Etsy and so if you're lucky you can import an empty module by doing something like this the photo here is a snapshot from the cheese shop sketch because that is where you can find Python code to install the websites name is cheese shop although

its domain spelled PYP i dot python that org i think there's some history about it being used to be called the cheese shop and so now it's still called the cheese shop but nobody says it except in recorded talks at PyCon but if you search there if

you search on the cheese shop for se wrapper because you want to find something it will wrap the Etsy API then ah you put in that search you'll find a webpage that looks like this this is an index of packages matching anti wrapper I'll zoom in just

about where the mouse pointer is on this first hit Python - Etsy so great there's some code on the cheese shop that will let you communicate with the Etsy API this is sweet but it says Python - Etsy is the name of the package some of you might have already

noticed that if you try to import something called Python - Etsy you will get a syntax error this doesn't make sense how can this thing be called Python - Etsy there's can't put a hyphen in a module name so the name of things on the cheese shop

is not the module you're installing it's the so-called distribution that happens to contain some module and who knows what modules it contains luckily this what explains on a cheese trap entry which you can see here this is just the Python - Etsy page

on pi PI dot and it says great it'll make it easy to interact with the Etsy API there's information on how to install it and in the initialization section down below it tells you that it'll make a module called Etsy so great if you have

this you can import Etsy some of you as student readers might have noticed that the installation instructions say sudo a pip install Etsy and the more astute will have noticed it says sub-p PIF install Etsy so this is a photo of a guy named Genki sudo he's

part of a band called world world order they make fantastic robot ask choreographed dance moves and the music to back it up I recommend finding some of their videos the point is this is what you should be thinking of when you think of sudo you should not be

thinking sudo pip install because sudo is an extremely powerful way to run any command the result of it are sort of unrecoverable for your system something you run on a Mac or Linux system with sudo can totally replace your operating system and if you're

on Windows it'll give you command not found so this is suboptimal also I want to take a brief digression to say how I first got really involved in programming in Python in 2001 I wanted to write some code to convert the high school newspapers PageMaker

6.5 multi-page printed monthly newspaper and generate an HTML website because the web is gonna be the future and I knew that Python was a great language to write programs in I've been learning C++ in high school but the computer in the trapezoid office

that was the high school newspaper I didn't have admin privilege dog privileges on it luckily as a teenage script Kitty this wasn't a big deal I downloaded a local privilege escalation vulnerability so that I could get a CMD prompt running as the quality

admin username system so that I could install on two point two or something ah people don't always have sudo they could tell them to run sudo and they can't it's kind of sad luckily there is a way to install Python packages for that meeting sudo

and I'll bring you back to sis top path in particular one of the entries in sis top path is inside your home directory or your users directory on Mac OS or the users folder or documents and settings depending on what version of Windows you're on there's

a place that Python has that it will look if you install things in the right way and there is a right way and that way is this pif install double - user Python - Etsy and that'll take this Python - Etsy thing look it up on pi PI it'll download the

source distribution from pi PI it'll succeed and it'll clean up I don't know why prints cleaning up I guess it removes a temporary directories so after you do this you'll be able to import Etsy and when you do that that Etsy module will tell

you that it came from inside your home directory so things look great I want to pause for a moment to reflect we've seen modules like the Etsy module we've seen distributions which are what you get from pi pi and we've seen tools we've just

seen one tool pip install double - user we haven't talked about any useful reason to use sudo yet we haven't talked about virtual end yet and that's fine for now so pip and pi PI aren't all ah don't always work the way you want and so I'm

gonna talk about a few of the failure modes there is by the way a brand of ice cream in India called quality spelled this way actually they stopped being allowed to be called ice cream because they fatten the milk with a vegetable fat so they're now quality

frozen desserts but anyway if you pip install double - user Etsy which is the different distribution than Python - Etsy so it's a totally different thing made by some totally unrelated people it happens to also create a module called Etsy f you install

[ ... ]

Nota: se han omitido las otras 4.156 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.