Open main menu

Changes

== Check Python ==Check the version of the default Python interpreter:<code>python --version</code> List the versions of python available:<code>ls /usr/bin/python*</code> Use <code>update-alternatives</code> to setup system-wide ability to choose Python interpreter. The one with the '''higher''' priority number will become the default.<br><code>update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1</code><br><code>update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2</code> Now we can list the choices:<code>update-alternatives --list python</code> And choose one:<code>update-alternatives --config python</code> We can also remove a choice if it's no longer an option on the system:<code>update-alternatives --remove python /usr/bin/python2.7</code> == Python Virtual Environments ==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">cdmkdir environmentscd environments/pyvenv my_envsource my_env/bin/activatepip install --upgrade pippip install soundscrapepip install soundscrape --upgradesoundscrape https://soundcloud.com/pianoman_weddings/coldplay</source></ref> Hynek Schlawack(from 2013)
* [https://hynek.me/talks/python-deployments/ Notes]
* [https://www.youtube.com/watch?v=RvbDCzroavY Video]
== Python Packaging ==
Christoph Haas discusses 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, easy_install, </code> == Basic PIP and Virtual Environments ==Do NOT (normally) use sudo with pip. Use a virtual environment. As of Python 3.4, aptthe command is now called <code>pyvenv</code> or simply <code>venv</code>. As of Python 3.6 <code>pyvenv</code> is '''deprecated''' in favor of using <code>python3 -m venv</yumcode> to help prevent any potential confusion as to which Python interpreter a virtual environment will be based on. '''python3''' is not generic. It represents the '''exact''' version you wish to use in your virtual environment. As an example, I needed to create a Python Virtual Environment to use the [https://workaroundgithub.orgcom/freephile/meza/issues/63#issuecomment-2020431602 Ansible Playbook Grapher]<source lang="bash">python3.11 -m venv myenv# .. some output ..source myenv/bin/easyactivate# maybe upgrade pippip install --upgrade pip# then install your local environment packagespip install what-i-want# done using this python?deactivate</source> You only use sudo or elevated permissions when you want to installstuff for the global, system-debianwide 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.
Stackoverflow says [http:* Installing a package is as simple as <code>pip install foo<//stackoverflow.com/questions/3220404/why-use-code>* Upgrades are <code>pipinstall -over-easy-installupgrade foo</ use code> * <code>pip over easy_install], but things have been changing over the past few years, so the futureuninstall foo</best practice may require a bit more digging.code> if you want to remove foo
== Basic PIP ==* Installing a package is as simple as <code>sudo pip install foo</code>* Upgrades are <code>sudo pip install --upgrade foo</code> * <code>sudo pip uninstall foo</code> if you want to remove foo{{References}}
[[Category:Python]]