Can we shed some definitive light on how python packaging and import works?

前端 未结 4 499
北海茫月
北海茫月 2021-01-30 00:36

I had my fair chance of getting through the python management of modules, and every time is a challenge: packaging is not what people do every day, and it becomes a burden to le

4条回答
  •  佛祖请我去吃肉
    2021-01-30 00:47

    I don't think import needs to be explored (Python's namespacing and importing functionality is intuitive IMHO).

    I use pip exclusively now. I haven't run into any issues with it.

    However, the topic of packaging and distribution is something worth exploring. Instead of giving a lengthy answer, I will say this:

    I learned how to package and distribute my own "packages" by simply copying how Pylons or many other open-source packages do it. I then combined that sort-of template with reading up of the docs to flesh it out even further and have come up with a solid distribution method.

    When you grok package management and distribution for python (distutils and pypi) it's actually quite powerful. I like it a lot.

    [edit]

    I also wanted to add in a bit about virtualenv. USE IT. I create a virtualenv for every project and I always use --no-site-packages; I install all the packages I need for that particular project (even if it's something common amongst them all, like lxml) inside the virtualev. It keeps everything isolated and it's much easier for me to maintain the grouping in my head (rather than trying to keep track of what's where and for which version of python!)

    [/edit]

提交回复
热议问题