Difference between revisions of "Python deployments"

From Freephile Wiki
Jump to navigation Jump to search
(pip is a pain in the penis)
(brief updates for 2017)
Line 1: Line 1:
Hynek Schlawack
+
See Digital Ocean's quick guide to [https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04 setting up a local Python programming environment], including [https://virtualenv.pypa.io/en/stable/ virtual environments], which is what I did for [https://github.com/Miserlou/SoundScrape SoundScrape]  Btw, SoundScrape is a neat tool to download sound files from SoundCloud.
 +
<ref>
 +
<source lang="bash">
 +
cd
 +
mkdir environments
 +
cd environments/
 +
pyvenv my_env
 +
source my_env/bin/activate
 +
pip install --upgrade pip
 +
pip install soundscrape
 +
pip install soundscrape --upgrade
 +
soundscrape https://soundcloud.com/pianoman_weddings/coldplay
 +
</source>
 +
</ref>
 +
 
 +
Hynek Schlawack (from 2013)
 
* [https://hynek.me/talks/python-deployments/ Notes]
 
* [https://hynek.me/talks/python-deployments/ Notes]
 
* [https://www.youtube.com/watch?v=RvbDCzroavY Video]
 
* [https://www.youtube.com/watch?v=RvbDCzroavY Video]
  
 
== Python Packaging ==
 
== Python Packaging ==
Christoph Haas discusses virtualenv, easy_install, pip, apt/yum
+
In the old days (2015) there were still debates about how to package Python and install stuff.  Now, it's settled. Use pip.  Easy_install is dead. See the [https://docs.python.org/3/installing/index.html docs]. Also note that <code>venv</code> is the successor to <code>virtualenv</code>
https://workaround.org/easy-install-debian
+
 
 +
== Basic PIP ==
 +
Do NOT (normally) use sudo with pip. Use a virtual environment:
 +
<source lang="bash">
 +
$ virtualenv myenv
 +
.. some output ..
 +
$ source myenv/bin/activate
 +
(myenv) $ pip install what-i-want
 +
</source>
 +
You only use sudo or elevated permissions when you want to install stuff for the global, system-wide Python installation.
  
Stackoverflow says [http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install/  use pip over easy_install], but things have been changing over the past few years, so the future/best practice may require a bit more digging.
+
It is best to use a virtual environment which isolates packages for you. That way you can play around without polluting the global python install.
  
== Basic PIP ==
+
As a bonus, virtualenv does not need elevated permissions.
pip is a fast-moving target and the packaged versions in Debian or Ubuntu are old and buggy.  So, you should get pip from upstream.
 
  
* Installing a package is as simple as <code>sudo pip install foo</code>
+
* Installing a package is as simple as <code>pip install foo</code>
* Upgrades are <code>sudo pip install --upgrade foo</code>  
+
* Upgrades are <code>pip install --upgrade foo</code>  
* <code>sudo pip uninstall foo</code> if you want to remove foo<ref>but you might have to resort to brute force like <code>sudo rm -rf /usr/local/lib/python2.7/dist-packages/dopy*</code> since old pip is buggy.  Or try without sudo.  Or just upgrade pip</ref>
+
* <code>pip uninstall foo</code> if you want to remove foo
  
 
{{References}}
 
{{References}}

Revision as of 09:52, 27 February 2017

See Digital Ocean's quick guide to setting up a local Python programming environment, including virtual environments, which is what I did for SoundScrape Btw, SoundScrape is a neat tool to download sound files from SoundCloud. [1]

Hynek Schlawack (from 2013)

Python Packaging[edit | edit source]

In the old days (2015) there were still debates about how to package Python and install stuff. Now, it's settled. Use pip. Easy_install is dead. See the docs. Also note that venv is the successor to virtualenv

Basic PIP[edit | edit source]

Do NOT (normally) use sudo with pip. Use a virtual environment:

$ virtualenv myenv
.. some output ..
$ source myenv/bin/activate
(myenv) $ pip install what-i-want

You only use sudo or elevated permissions when you want to install stuff for the global, system-wide Python installation.

It is best to use a virtual environment which isolates packages for you. That way you can play around without polluting the global python install.

As a bonus, virtualenv does not need elevated permissions.

  • Installing a package is as simple as pip install foo
  • Upgrades are pip install --upgrade foo
  • pip uninstall foo if you want to remove foo

References[edit source]

  1. cd
    mkdir environments
    cd environments/
    pyvenv my_env
    source my_env/bin/activate
    pip install --upgrade pip
    pip install soundscrape
    pip install soundscrape --upgrade
    soundscrape https://soundcloud.com/pianoman_weddings/coldplay