[Python-ideas] install pip packages from Python prompt
Steve Barnes
gadgetsteve at live.co.uk
Wed Nov 1 04:17:20 EDT 2017
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.
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.
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).
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.
--
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
More information about the Python-ideas
mailing list