[Python-ideas] install pip packages from Python prompt

Wes Turner wes.turner at gmail.com
Wed Nov 1 09:41:11 EDT 2017


On Wednesday, November 1, 2017, Steve Barnes <gadgetsteve at live.co.uk> wrote:

>
>
> On 01/11/2017 06:54, Wes Turner wrote:
> > Suggestions to help to minimize unnecessary logged bandwidth use and
> > even work with a closed loop LAN:
> >
> > This reads from the filesystem:
> >
> >      import requests
> >
> > This would read from the PyPi service over the network bandwidth:
> >
> >     #!pip install -U requests
> >     #%run pip install -U requests
> >
> >     #pip('install -U requests')
> >
> > This doesn't work because you SHOULD restart the interpreter after
> > running pip (because imports are cached):
> >
> >      import requests
> >      !pip install -U requests
> >      import requests
> >
> > Some tips on running educational environments for beginners (optionally
> > in a lab):
> >
> <Snipped a lot of good stuff>
>
> One tip that I have used when teaching python in a closed, (sometimes
> internet free environment), was to pre-prepare by, in an on-line
> environment:
>
>   1. Create a virtual environment with the version of Python that I am
> going to be teaching on the target platform
>   2. Activate that environment
>   3. Ensure that I am On-line
>   4. Download the pip install packages that I know I will need by using
> `pip download` to download but not install the packages, ideally using
> the -r requirements.txt syntax, (plus any windows specific builds from
> Christoph Gohlke's site).
>   5. Go Off-line and run pip install with the downloaded package - if I
> hit any errors due to packages having unspecified dependencies add those
> to the requirements list and repeat from 3. (While I am at it I often
> log an issue with the package maintainer).
>   6. A fast, personal, run through my lesson plan to ensure that I
> haven't missed anything.
>
> I normally also download a few goodies that might not be essential to
> the lesson but that can act as a teaser for the more interested students.
>
> At the start of the first lesson I give the students the downloaded
> packages directory, usually on a USB key, and get them to pip install
> them while explaining the difference between local and on-line
> installation.


That works. You could also host the packages with devpi or just a static
HTTP server.

As a transparent cache, if you test your ``requirements.txt`` with each
OS/CPU_architecture combination, DevPi will store and serve each package to
everyone at once.

So do you do (in a virtualenv):

  pip install --download ./dir -r requirements.txt

And then

  pip install --no-index --find-links ./dir -r requirements.text

Like in the pip docs?

https://pip.pypa.io/en/stable/user_guide/#installing-from-local-packages

DevPi can host package documentation.
https://devpi.net/docs/devpi/devpi/stable/+doc/userman/devpi_packages.html#uploading-documentation
*

GitLab Pages can host package documentation and any static HTML pages (e.g.
the CPython docs) alongside **the source**
https://docs.gitlab.com/ce/user/project/pages/index.html

https://github.com/python/cpython/tree/3.6/Doc


ReadTheDocs can host Sphinx docs and can be run in a Docker container for
an internet-free LAN:
https://github.com/rtfd/readthedocs-docker-images


>
> I know that I could save having to get the students to run pip by
> packaging up the virtual environment as a portable, or using by
> pyInstaller, but having them run pip on the local downloads gives me a
> chance to explain how to do it in the wild.


AFAIU, YMMV with ``virtualenv --relocatable``; and it certainly doesn't do
all combinations of OS and processor architecture:

https://virtualenv.pypa.io/en/stable/userguide/#making-environments-relocatable

itertools.combinations(
  ['win', 'mac', 'lin', '', '686', 'x86_64', 'ARM'], 2)


>
> BTW while Docker is great for this it is a whole other learning
> experience, (plus getting it running with some corporate security &
> anti-virus can be quite a challenge).


Yeah, hosting Docker containers with Kubernetes across a couple extra
workstations is initially more work than creating a few USB keys and
waiting for everyone's virtualenvs to converge (with ``$ pip install``,
``!PIP_INDEX='' pip install``, and now a new pip GUI button press sequence).


>
> These USB keys are often re-used by other co-workers as a getting
> started or after my computer got changed/re-imaged starting point.


Wouldn't it be create if, just like oldschool floppies, there was a way to
break off the sliding write protect tab of a USB stick?

https://en.wikipedia.org/wiki/USB_flash_drive_security#Malware_infections

CD-ROM and DVD-ROM drives seem to be more and more scare these days.


>
> --
> Steve (Gadget) Barnes
> Any opinions in this message are my personal opinions and do not reflect
> those of my employer.
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <javascript:;>
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171101/ba637cdd/attachment.html>


More information about the Python-ideas mailing list