Release Date: Dec. 19, 2017
Windows users: If installing Python 3.6 as a non-privileged user, you may need to escalate to administrator privileges to install an update to your C runtime libraries. Windows users: There are now 'web-based' installers for Windows platforms; the installer will download the needed software components at installation time. This guide is written for Python 3, however, these instructions should work fine on Python 2.7—if you are still using it, for some reason. Make sure you’ve got Python & pip ¶ Before you go any further, make sure you have Python and that it’s available from your command line.
Python 3.6.4 was the fourth maintenance release of Python 3.6.
There are now newer security-fix releases of Python 3.6 that supersede 3.6.4 and Python 3.8 is now the latest feature release of Python 3. Get the latest releases of 3.6.x and 3.8.x here. Python 3.6.8 is planned to be the last bugfix releasefor 3.6.x. Following the release of 3.6.8, we plan to provide security fixes for Python 3.6 as needed through 2021, five years following its initial release.
Among the new major new features in Python 3.6 were:
Version | Operating System | Description | MD5 Sum | File Size | GPG |
---|---|---|---|---|---|
Gzipped source tarball | Source release | 9de6494314ea199e3633211696735f65 | 22710891 | SIG | |
XZ compressed source tarball | Source release | 1325134dd525b4a2c3272a1a0214dd54 | 16992824 | SIG | |
Mac OS X 64-bit/32-bit installer | Mac OS X | for Mac OS X 10.6 and later | 9fba50521dffa9238ce85ad640abaa92 | 27778156 | SIG |
Windows help file | Windows | 17cc49512c3a2b876f2ed8022e0afe92 | 8041937 | SIG | |
Windows x86-64 embeddable zip file | Windows | for AMD64/EM64T/x64, not Itanium processors | d2fb546fd4b189146dbefeba85e7266b | 7162335 | SIG |
Windows x86-64 executable installer | Windows | for AMD64/EM64T/x64, not Itanium processors | bee5746dc6ece6ab49573a9f54b5d0a1 | 31684744 | SIG |
Windows x86-64 web-based installer | Windows | for AMD64/EM64T/x64, not Itanium processors | 21525b3d132ce15cae6ba96d74961b5a | 1320128 | SIG |
Windows x86 embeddable zip file | Windows | 15802be75a6246070d85b87b3f43f83f | 6400788 | SIG | |
Windows x86 executable installer | Windows | 67e1a9bb336a5eca0efcd481c9f262a4 | 30653888 | SIG | |
Windows x86 web-based installer | Windows | 6c8ff748c554559a385c986453df28ef | 1294088 | SIG |
This tutorial walks you through installing and using Python packages.
It will show you how to install and use the necessary tools and make strongrecommendations on best practices. Keep in mind that Python is used for a greatmany different purposes, and precisely how you want to manage your dependenciesmay change based on how you decide to publish your software. The guidancepresented here is most directly applicable to the development and deployment ofnetwork services (including web applications), but is also very well suited tomanaging development and testing environments for any kind of project.
Note
This guide is written for Python 3, however, these instructionsshould work fine on Python 2.7—if you are still using it, for some reason.
Before you go any further, make sure you have Python and that it’s availablefrom your command line. You can check this by simply running:
You should get some output like 3.6.2
. If you do not have Python, pleaseinstall the latest 3.x version from python.org or refer to theInstalling Python section of this guide.
Note
If you’re newcomer and you get an error like this:
It’s because this command is intended to be run in a shell (also calleda terminal or console). See the Python for Beginnersgetting started tutorial for an introduction to using your operatingsystem’s shell and interacting with Python.
Additionally, you’ll need to make sure you have pip available. You cancheck this by running:
If you installed Python from source, with an installer from python.org, orvia Homebrew you should already have pip. If you’re on Linux and installedusing your OS package manager, you may have to install pip separately.
Pipenv is a dependency manager for Python projects. If you’re familiarwith Node.js’ npm or Ruby’s bundler, it is similar in spirit to thosetools. While pip can install Python packages, Pipenv is recommended asit’s a higher-level tool that simplifies dependency management for common usecases.
Use pip
to install Pipenv:
Note
This does a user installation to prevent breaking any system-widepackages. If pipenv
isn’t available in your shell after installation,you’ll need to add the user base’s binary directory to your PATH
.
On Linux and macOS you can find the user base binary directory by runningpython-msite--user-base
and adding bin
to the end. For example,this will typically print ~/.local
(with ~
expanded to theabsolute path to your home directory) so you’ll need to add~/.local/bin
to your PATH
. You can set your PATH
permanently bymodifying ~/.profile.
On Windows you can find the user base binary directory by runningpy-msite--user-site
and replacing site-packages
withScripts
. For example, this could returnC:UsersUsernameAppDataRoamingPython36site-packages
so you wouldneed to set your PATH
to includeC:UsersUsernameAppDataRoamingPython36Scripts
. You can set youruser PATH
permanently in the Control Panel. You may need to logout for the PATH
changes to take effect.
Pipenv manages dependencies on a per-project basis. To install packages,change into your project’s directory (or just an empty directory for thistutorial) and run:
Pipenv will install the excellent Requests library and create a Pipfile
for you in your project’s directory. The Pipfile is used to track whichdependencies your project needs in case you need to re-install them, such aswhen you share your project with others. You should get output similar to this(although the exact paths shown will vary):
Now that Requests is installed you can create a simple main.py
file touse it:
Then you can run this script using pipenvrun
:
You should get output similar to this:
Using $pipenvrun
ensures that your installed packages are available toyour script. It’s also possible to spawn a new shell that ensures all commandshave access to your installed packages with $pipenvshell
.
Congratulations, you now know how to install and use Python packages! ✨ 🍰 ✨