Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Packaging Simplified by Asheesh Laroia

Python Packaging Simplified by Asheesh Laroia

Presented at PyCon 2014

PyCon 2014

April 12, 2014
Tweet

More Decks by PyCon 2014

Other Decks in Technology

Transcript

  1. Goals 1. Be able to install 2. Be able to

    distribute 3. Know how to learn more
  2. Goals 1. Be able to install 2. Be able to

    distribute 3. Know how to learn more
  3. Goals 1. Be able to install 2. Be able to

    distribute 3. Know how to learn more
  4. >>> import sys >>> sys.path ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux- gnu', '/usr/lib/python2.7/lib-tk',

    '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/me/.local/lib/python2.7/site- packages', '/usr/local/lib/python2.7/dist- packages', '/usr/lib/python2.7/dist-packages',
  5. >>> import sys >>> sys.path ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux- gnu', '/usr/lib/python2.7/lib-tk',

    '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/me/.local/lib/python2.7/site- packages', '/usr/local/lib/python2.7/dist- packages', '/usr/lib/python2.7/dist-packages',
  6. $ sudp pip install python-etsy $ sudp pip install python-etsy

    Genki Sudo Genki Sudo World Order World Order
  7. $ pip install --user python-etsy Downloading/unpacking python-etsy Downloading python-etsy- 0.1.2.tar.gz

    Successfully installed python-etsy Cleaning up... $ python >>> import etsy
  8. $ pip install --user python-etsy Downloading/unpacking python-etsy Downloading python-etsy- 0.1.2.tar.gz

    Successfully installed python-etsy Cleaning up... $ python >>> import etsy >>> etsy <module 'etsy' from '/home/me/.local/lib/python2.7/ site-packages/etsy/__init__.pyc'>
  9. # module # module >>> import etsy >>> import etsy

    # distribution # distribution $ pip install --user python-etsy $ pip install --user python-etsy
  10. # module # module >>> import etsy >>> import etsy

    # distribution # distribution $ pip install --user python-etsy $ pip install --user python-etsy # tools # tools $ pip install --user $ pip install --user
  11. # module # module >>> import etsy >>> import etsy

    # distribution # distribution $ pip install --user python-etsy $ pip install --user python-etsy # tools # tools $ pip install --user $ pip install --user # no sudo, no virtualenv # no sudo, no virtualenv
  12. $ pip install --user etsy $ pip install --user etsy

    ValueError: Invalid IPv6 URL ValueError: Invalid IPv6 URL
  13. PyPI: PyPI: Wrong or missing no Wrong or missing no

    download URLs verification download URLs verification
  14. PyPI: PyPI: Wrong or missing no Wrong or missing no

    download URLs verification download URLs verification (fixed w/ pip 1.5) (remains) (fixed w/ pip 1.5) (remains)
  15. pip: pip: under python 3.2: under python 3.2: $ pip

    install --user jinja2 $ pip install --user jinja2 Downloading/unpacking jinja2 Downloading/unpacking jinja2
  16. pip: pip: under python 3.2: under python 3.2: $ pip

    install --user jinja2 $ pip install --user jinja2 Downloading/unpacking jinja2 Downloading/unpacking jinja2 # ... # ...
  17. File "jinja2/runtime.py", File "jinja2/runtime.py", line 44 line 44 SyntaxError: invalid

    syntax SyntaxError: invalid syntax Successfully installed jinja2 Successfully installed jinja2 Cleaning up... Cleaning up...
  18. >>> import jinja2 >>> import jinja2 File File "…/jinja2/environment.py", line

    "…/jinja2/environment.py", line 639 639 u'...'.encode('iso-8859-15') u'...'.encode('iso-8859-15') ^ ^ SyntaxError: invalid syntax SyntaxError: invalid syntax
  19. $ python >>> import etsy $ pip uninstall etsy Cannot

    uninstall requirement etsy, not installed
  20. $ python >>> import etsy $ pip uninstall etsy Cannot

    uninstall requirement etsy, not installed $ pip uninstall python-etsy
  21. $ pip install --user python-etsy $ pip install --user python-etsy

    # ... # ... Running setup.py egg_info Running setup.py egg_info for package python-etsy for package python-etsy
  22. $ pip install --user python-etsy $ pip install --user python-etsy

    # ... # ... Running Running setup.py egg_info setup.py egg_info for package python-etsy for package python-etsy
  23. $ pip pip: Command not found. $ # download get-pip.py

    $ python get-pip.py --user $ pip pip: Command not found.
  24. $ pip pip: Command not found. $ # download get-pip.py

    $ python get-pip.py --user $ pip pip: Command not found. $ PATH=~/.local/bin:$PATH
  25. $ pip pip: Command not found. $ # download get-pip.py

    $ python get-pip.py --user $ pip pip: Command not found. $ PATH=~/.local/bin:$PATH $ pip --version pip 1.5.4 from /home/me/.local/lib/python2.7/ site-packages (python 2.7)
  26. ~ $ cd get-octopi ~/get-octopi $ ls octopi_getter.py # time

    passes ~/get-octopi $ ls octopi_getter.py setup.py LICENSE
  27. $ python setup.py sdist upload python setup.py sdist upload running

    sdist running check creating wikimarkup-1.0 creating dist Creating tar archive running upload
  28. $ python setup.py sdist upload python setup.py sdist upload running

    sdist running check creating wikimarkup-1.0 creating dist Creating tar archive running upload
  29. $ python setup.py sdist upload python setup.py sdist upload running

    sdist running check creating get-octopi-1.0 creating dist Creating tar archive running upload
  30. $ python setup.py sdist upload python setup.py sdist upload running

    sdist running check creating get-octopi-1.0 creating dist Creating tar archive running upload Submitting dist/get-octopi- 1.0.tar.gz to https://pypi.python.org/pypi
  31. from distutils.core import setup # within setup() entry_points = {

    'console_scripts': [ 'get-now = octopi_getter:main', ], },
  32. from distutils.core import setup # within setup() entry_points = {

    'console_scripts': [ 'get-now = octopi_getter:main', ], }, # finally $ pip install --user .
  33. $ get-now $ get-now get-now: Command not found. get-now: Command

    not found. $ PATH=$PATH:~/.local/bin $ PATH=$PATH:~/.local/bin
  34. $ get-now $ get-now Logging into Etsy... Logging into Etsy...

    Identifying octopi... Identifying octopi...
  35. $ get-now $ get-now Logging into Etsy... Logging into Etsy...

    Identifying octopi... Identifying octopi... Purchasing... Purchasing...
  36. $ get-now $ get-now Logging into Etsy... Logging into Etsy...

    Identifying octopi... Identifying octopi... Purchasing... Purchasing... Purchased. You spent $325.21. Purchased. You spent $325.21.
  37. $ pip install --user . $ python >>> import octopi_getter

    >>> octopi_getter <module ... from '.../site- packages/octopi_getter.pyc'>
  38. $ pip install --user --editable . # aka setup.py develop

    --user $ python >>> import octopi_getter >>> octopi_getter <module ... from '/home/me/ get-octopi/octopi_getter.pyc'>
  39. $ pip install --user --editable . # aka setup.py develop

    --user $ python >>> import octopi_getter >>> octopi_getter <module ... from '/home/me/ get-octopi/octopi_getter.pyc'>
  40. from distutils.core import setup ## safe and featureless from setuptools

    import setup ## pip provides this for free from distribute import setup
  41. $ pip install --user --editable . # ... CONFLICT $

    virtualenv . New python executable in ./bin/python Installing setuptools, pip...done. $ source bin/activate (get-octopi) $
  42. $ pip install --user --editable . # ... CONFLICT $

    virtualenv . New python executable in ./bin/python Installing setuptools, pip...done. $ source bin/activate (get-octopi) $ pip install --editable .
  43. $ pip install --user --editable . # ... CONFLICT $

    virtualenv . New python executable in ./bin/python Installing setuptools, pip...done. $ source bin/activate (get-octopi) $ pip install -e .
  44. (get-octopi) $ pip install (get-octopi) $ pip install --user --editable

    . --user --editable . Can not perform a '--user' Can not perform a '--user' install. User site-packages are install. User site-packages are not visible in this virtualenv. not visible in this virtualenv.
  45. (get-octopi) $ pip install lxml unable to execute 'x86_64-linux-gnu- gcc':

    No such file or directory error: command 'x86_64-linux-gnu- gcc' failed with exit status 1
  46. $ sudo apt-get install python-lxml $ python >>> import lxml

    >>> $ pip install lxml Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/lib/python2.7/dist-packages Cleaning up...
  47. $ sudo apt-get install python-lxml $ python >>> import lxml

    >>> $ source bin/activate (get-octopi) $ python >>> import lxml ImportError: No module called lxml.
  48. $ sudo apt-get install python-lxml $ python >>> import lxml

    >>> $ source bin/activate (get-octopi) $ python >>> import lxml ImportError: No module called lxml $ sudo apt-get build-dep python-lxml
  49. - no virtualenv - no pip install - no C

    compiler - purely sqlite
  50. # No compiler, no problem # Load Python Imaging Library

    try: import Image except: import sys sys.modules['Image'] = ( sys.modules['sys'])
  51. # No compiler, no problem # Load Python Imaging Library

    try: import Image except: # beloved Django ImageField import sys sys.modules['Image'] = ( sys.modules['sys'])
  52. # settings.py DATABASES = { 'default': { 'NAME': 'site.db', 'ENGINE':

    'sqlite3', }, } if os.environ.get('USE_MYSQL', ''): DATABASES['default'] = ( OTHER_DATABASES['mysql'])
  53. $ time pip install twisted 41.277s total $ time pip

    install twisted 5.653s total PIP_DOWNLOAD_CACHE PIP_FIND_LINKS PIP_USE_WHEEL PIP_WHEEL_DIR
  54. $ time pip install twisted 41.277s total $ time pip

    install twisted 5.653s total http://pip2014.com/
  55. Goals 1. Be able to install 2. Be able to

    distribute 3. Know how to learn more