Effective PyCharm Transcripts
Chapter: Packages
Lecture: Concepts: Packaging
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Let's review some of the concepts that you saw while we were working with packages in our demo. So we saw that we can load existing packages
0:11
here we're using requests.cookies and it's easy for us to just open up requests PyCharm knows that this is a package,
0:20
it knows that when it imports stuff it has to say requests. for the various things so it's really good at working with packages
0:27
that maybe you got off of GitHub or wherever. So this is nice, one of the things we need to do actually to be able to leverage that package,
0:37
to run it and import it into say our program for getting some kind of package, trying to use it and see how it works, and making changes
0:46
maybe eventually with the goal of doing a PR back to the original package owner or something like that
0:50
is you have to install it, or more importantly set it up in development mode so you can do that by just going to tools run setup task
0:58
down here you get all of the options if you type develop then it'll go and install all the dependencies
1:05
and register requests locally, so that at least that virtual environment knows to go back in local right here to run this local copy of Requests.
1:15
Now on the other hand, we might want to create a new package from scratch not work with someone else's,
1:22
so we can come down here and say new Python package and this honestly doesn't do very much for you it creates a directory with a __init__
1:29
so this works for packages or subpackages you could just create a directory and put a Python file name __init__ in there if you want
1:36
but this I guess saves you a step, and it sort of follows the convention a little bit more closely. So these packages are not particularly useful
1:44
if you can't install them to use them elsewhere so we can go and create a setup.py and you can just go to tools create setup.py
1:52
this doesn't work if you already have a setup.py anywhere in your project so just be aware of that.
1:57
Look at this dialogue, it asks you all the pertinent questions what is the name, what's the version, what's the license and so on and so on,
2:03
I hit OK and then boom— out pops a setup method ready to go and a setup.py. Now traditionally PyCharm has used distutils.core
2:15
to get setup and just recently they switch to the setup tools version and that's important because the older versions don't have the develop option
2:24
so Python setup.py develop, that didn't use to work, just by pressing the button as long as you're using 2017.3 or above though
2:33
it looks like everything is golden. If for some reason you don't have that, you can just alter the import statement at the top
2:41
and then you are ready to roll, your new package is ready to be set up and used or tested or whatever you want to do with it.