Updating Python On Mac



These instructions cover how to get a working copy of the source code and acompiled version of the CPython interpreter (CPython is the version of Pythonavailable from https://www.python.org/). It also gives an overview of thedirectory structure of the CPython source code.

Since Python is open-source, you can run it on Windows, Mac, Linux or any other platform. Your programs will work without any need to change it for every machine. GUI Programming. You can use it to develop a GUI (Graphical User Interface). One way to do this is through Tkinter. Large Python Library. Python provides you with a large.

  • The arcade library is a modern Python framework for crafting games with compelling graphics and sound. Object-oriented and built for Python 3.6 and up, arcade provides the programmer with a modern set of tools for crafting great Python game experiences. In this tutorial, you’ll learn how to: Install the arcade library; Draw items on the screen.
  • 49 Mac Users Customize the Tkinter Buttons 50 Data Entry validation 51 Auto-complete Entry widgets 52 Adding scrollable frames the basics 53 Adding scrollable frames a more complex case 54 Closing the application 55 Starting the application outside of Pycharm 56 Creating an SQLite database 57 Saving your workspace to the database.

Alternatively, if you have Docker installed youmight want to use our official images. Thesecontain the latest releases of several Python versions, along with git head,and are provided for development and testing purposes only.

See also

The Quick Reference gives brief summary of the process frominstalling git to submitting a pull request.

1.1. Install git

CPython is developed using git for version control. The gitcommand line program is named git; this is also used to refer to gititself. git is easily available for all common operating systems.

  • Install

    As the CPython repo is hosted on GitHub, please refer to either theGitHub setup instructionsor the git project instructions for step-by-stepinstallation directions. You may also want to consider a graphical clientsuch as TortoiseGit orGitHub Desktop.

  • Configure

    Configure your name and email and createan SSH keyas this will allow you to interact with GitHub without typing a usernameand password each time you execute a command, such as gitpull,gitpush, or gitfetch. On Windows, you should alsoenable autocrlf.

1.2. Get the source code¶

The CPython repo is hosted on GitHub. To get a copy of the source code you shouldfork the Python repository on GitHub, create a localclone of your personal fork, and configure the remotes.

You will only need to execute these steps once:

  1. Go to https://github.com/python/cpython.

  2. Press Fork on the top right.

  3. When asked where to fork the repository, choose to fork it to your username.

  4. Your fork will be created at https://github.com/<username>/cpython.

  5. Clone your GitHub fork (replace <username> with your username):

    (You can use both SSH-based or HTTPS-based URLs.)

  6. Configure an upstream remote:

  7. Verify that your setup is correct:

If you did everything correctly, you should now have a copy of the codein the cpython directory and two remotes that refer to your own GitHub fork(origin) and the official CPython repository (upstream).

If you want a working copy of an already-released version of Python,i.e., a version in maintenance mode, you can checkouta release branch. For instance, to checkout a working copy of Python 3.8,do gitcheckout3.8.

You will need to re-compile CPython when you do such an update.

Do note that CPython will notice that it is being run from a working copy.This means that if you edit CPython’s source code in your working copy,changes to Python code will be picked up by the interpreter for immediateuse and testing. (If you change C code, you will need to recompile theaffected files as described below.)

Patches for the documentation can be made from the same repository; seeDocumenting Python.

1.3. Compile and build¶

CPython provides several compilation flags which help with debugging variousthings. While all of the known flags can be found in theMisc/SpecialBuilds.txt file, the most critical one is the Py_DEBUG flagwhich creates what is known as a “pydebug” build. This flag turns on variousextra sanity checks which help catch common issues. The use of the flag is socommon that turning on the flag is a basic compile option.

You should always develop under a pydebug build of CPython (the only instance ofwhen you shouldn’t is if you are taking performance measurements). Even whenworking only on pure Python code the pydebug build provides several usefulchecks that one should not skip.

1.3.1. UNIX¶

The core CPython interpreter only needs a C compiler to be built,however, some of the extension modules will need development headersfor additional libraries (such as the zlib library for compression).Depending on what you intend to work on, you might need to install theseadditional requirements so that the compiled interpreter supports thedesired features.

If you want to install these optional dependencies, consult theInstall dependencies section below.

If you don’t need to install them, the basic steps for building Pythonfor development is to configure it and then compile it.

Configuration is typically:

More flags are available to configure, but this is the minimum you shoulddo to get a pydebug build of CPython.

Note

You might need to run makeclean before or after re-running configurein a particular build directory.

Once configure is done, you can then compile CPython with:

This will build CPython with only warnings and errors being printed tostderr and utilize up to 2 CPU cores. If you are using a multi-core machinewith more than 2 cores (or a single-core machine), you can adjust the numberpassed into the -j flag to match the number of cores you have (or if yourversion of Make supports it, you can use -j without a number and Makewill not limit the number of steps that can run simultaneously.).

At the end of the build you should see a success message, possibly followedby a list of extension modules that haven’t been built because theirdependencies were missing:

If the build failed and you are using a C89 or C99-compliant compiler,please open a bug report.

Mac

If you decide to Install dependencies, you will need to re-run bothconfigure and make.

Once CPython is done building you will then have a working buildthat can be run in-place; ./python on most machines (and what is used inall examples), ./python.exe wherever a case-insensitive filesystem is used(e.g. on OS X by default), in order to avoid conflicts with the Pythondirectory. There is normally no need to install your built copyof Python! The interpreter will realize where it is being run fromand thus use the files found in the working copy. If you are worriedyou might accidentally install your working copy build, you can add--prefix=/tmp/python to the configuration step. When running from yourworking directory, it is best to avoid using the --enable-shared flagto configure; unless you are very careful, you may accidentally runwith code from an older, installed shared Python library rather than fromthe interpreter you just built.

1.3.1.1. Clang¶

If you are using clang to build CPython, some flags you might want to set toquiet some standard warnings which are specifically superfluous to CPython are-Wno-unused-value-Wno-empty-body-Qunused-arguments. You can set yourCFLAGS environment variable to these flags when running configure.

If you are using clang with ccache, turn off the noisyparentheses-equality warnings with the -Wno-parentheses-equality flag.These warnings are caused by clang not having enough information to detectthat extraneous parentheses in expanded macros are valid, because thepreprocessing is done separately by ccache.

If you are using LLVM 2.8, also use the -no-integrated-as flag in order tobuild the ctypes module (without the flag the rest of CPython willstill build properly).

1.3.2. Windows¶

For a quick guide to building you can read this documentation from VictorStinner.

Python 3.6 and later can use Microsoft Visual Studio 2017. You can downloadand use any of the free or paid versions of Visual Studio 2017.

When installing Visual Studio 2017, select the Python development workloadand the optional Python native development tools component to obtain all ofthe necessary build tools. If you do not already have git installed, you canfind git for Windows on the Individual components tab of the installer.

Note

If you want to build MSI installers, be aware that the build toolchainfor them has a dependency on the Microsoft .NET Framework Version 3.5 (whichmay not be configured on recent versions of Windows, such as Windows 10). Ifyou are building on a recent Windows version, use the Control Panel (Programs| Programs and Features | Turn Windows Features on or off) and ensure that theentry “.NET Framework 3.5 (includes .NET 2.0 and 3.0)” is enabled.

Your first build should use the command line to ensure any external dependenciesare downloaded:

After this build succeeds, you can open the PCBuildpcbuild.sln solution inVisual Studio to continue development.

See the readme for more details on what other software is necessary and howto build.

Note

Python 2.7 uses Microsoft Visual Studio 2008, which is most easilyobtained through an MSDN subscription. To use the build files in thePCbuild directory you will also need Visual Studio 2010, see the 2.7readme for more details. If you have VS 2008 but not 2010 you can use thebuild files in the PC/VS9.0 directory, see the VS9 readme for details.

Note

If you are using the Windows Subsystem for Linux (WSL), clone therepository from a native Windows terminal program like cmd.exe command promptor PowerShell as well as use a build of git targeted for Windows, e.g., theofficial one from https://git-scm.com. Otherwise, Visual Studio willnot be able to find all the project’s files and will fail the build.

1.4. Install dependencies¶

This section explains how to install additional extensions (e.g. zlib)on Linux and macOs/OS X. On Windows,extensions are already included and built automatically.

1.4.1. Linux¶

For UNIX based systems, we try to use system libraries whenever available.This means optional components will only build if the relevant system headersare available. The best way to obtain the appropriate headers will vary bydistribution, but the appropriate commands for some popular distributionsare below.

On Fedora, Red Hat Enterprise Linux and other yum based systems:

On Fedora and other DNF based systems:

On Debian, Ubuntu, and other apt based systems, try to get thedependencies for the Python you’re working on by using the apt command.

First, make sure you have enabled the source packages in the sources list.You can do this by adding the location of the source packages, includingURL, distribution name and component name, to /etc/apt/sources.list.Take Ubuntu Bionic for example:

For other distributions, like Debian, change the URL and names to correspondwith the specific distribution.

Then you should update the packages index:

Now you can install the build dependencies via apt:

If that package is not available for your system, try reducing the minorversion until you find a package that is available.

1.4.2. macOS and OS X¶

For macOS systems (versions 10.12+) and OS X 10.9 and later,the Developer Tools can be downloaded and installed automatically;you do not need to download the complete Xcode application.

If necessary, run the following:

This will also ensure that the system header files are installed into/usr/include.

On Mac OS X systems (versions 10.0 - 10.7) and OS X 10.8, use the Ccompiler and other development utilities provided by Apple’s Xcode DeveloperTools. The Developer Tools are not shipped with Mac OS X.

For these older releases (versions 10.0 - 10.8), you will need to download either thecorrect version of the Command Line Tools, if available, or install them from thefull Xcode app or package for that OS X release. Older versions may beavailable either as a no-cost download through Apple’s App Store or fromthe Apple Developer web site.

Also note that OS X does not include several libraries used by the Pythonstandard library, including libzma, so expect to see some extension modulebuild failures unless you install local copies of them. As of OS X 10.11,Apple no longer provides header files for the deprecated system version ofOpenSSL which means that you will not be able to build the _ssl extension.One solution is to install these libraries from a third-party packagemanager, like Homebrew or MacPorts, and then add the appropriate pathsfor the header and library files to your configure command. For example,

with Homebrew:

and configure Python versions >= 3.7:

or configure Python versions < 3.7:

and make:

or MacPorts:

and configure:

and make:

There will sometimes be optional modules added for a new release whichwon’t yet be identified in the OS level build dependencies. In those cases,just ask for assistance on the core-mentorship list. If working on bugfixes for Python 2.7, use python in place of python3 in the abovecommands.

Explaining how to build optional dependencies on a UNIX based system withoutroot access is beyond the scope of this guide.

Note

While you need a C compiler to build CPython, you don’t need anyknowledge of the C language to contribute! Vast areas of CPython arewritten completely in Python: as of this writing, CPython contains slightlymore Python code than C.

1.5. Regenerate configure

If a change is made to Python which relies on some POSIX system-specificfunctionality (such as using a new system call), it is necessary to update theconfigure script to test for availability of the functionality.

Python’s configure script is generated from configure.ac using Autoconf.Instead of editing configure, edit configure.ac and then runautoreconf to regenerate configure and a number of other files (such aspyconfig.h).

When submitting a patch with changes made to configure.ac, you should alsoinclude the generated files.

Note that running autoreconf is not the same as running autoconf. Forexample, autoconf by itself will not regenerate pyconfig.h.in.autoreconf runs autoconf and a number of other tools repeatedly as isappropriate.

Python’s configure.ac script typically requires a specific version ofAutoconf. At the moment, this reads: AC_PREREQ(2.69).

If the system copy of Autoconf does not match this version, you will need toinstall your own copy of Autoconf.

1.6. Troubleshoot the build¶

This section lists some of the common problems that may arise during thecompilation of Python, with proposed solutions.

1.6.1. Avoid recreating auto-generated files¶

Under some circumstances you may encounter Python errors in scripts likeParser/asdl_c.py or Python/makeopcodetargets.py while running make.Python auto-generates some of its own code, and a full build from scratch needsto run the auto-generation scripts. However, this makes the Python build requirean already installed Python interpreter; this can also cause version mismatcheswhen trying to build an old (2.x) Python with a new (3.x) Python installed, orvice versa.

To overcome this problem, auto-generated files are also checked into theGit repository. So if you don’t touch the auto-generation scripts, there’sno real need to auto-generate anything.

1.7. Editors and Tools¶

Python is used widely enough that practically all code editors have some formof support for writing Python code. Various coding tools also include Pythonsupport.

For editors and tools which the core developers have felt some special commentis needed for coding in Python, see Additional Resources.

1.8. Directory structure¶

There are several top-level directories in the CPython source tree. Knowing whateach one is meant to hold will help you find where a certain piece offunctionality is implemented. Do realize, though, there are always exceptions toevery rule.

Doc
The official documentation. This is what https://docs.python.org/ uses.See also Building the documentation.
Grammar
Contains the EBNF grammar file forPython.
Include
Contains all interpreter-wide header files.
Lib
The part of the standard library implemented in pure Python.
Mac
Mac-specific code (e.g., using IDLE as an OS X application).
Misc
Things that do not belong elsewhere. Typically this is varying kinds ofdeveloper-specific documentation.
Modules
The part of the standard library (plus some other code) that is implementedin C.
Objects
Code for all built-in types.
PC
Windows-specific code.
PCbuild
Build files for the version of MSVC currently used for the Windowsinstallers provided on python.org.
Parser
Code related to the parser. The definition of the AST nodes is also kepthere.
Programs
Source code for C executables, including the main function for theCPython interpreter (in versions prior to Python 3.5, these files arein the Modules directory).
Python
The code that makes up the core CPython runtime. This includes thecompiler, eval loop and various built-in modules.
Tools
Various tools that are (or have been) used to maintain Python.

This guide is a comprehensive resource for contributingto Python – for both new and experienced contributors. It ismaintained by the samecommunity that maintains Python. We welcome your contributions to Python!

Quick Reference¶

Here are the basic steps needed to get set up and contribute apatch. This is meant as a checklist, once you know the basics. For completeinstructions please see the setup guide.

  1. Install and set up Git and other dependencies(see the Git Setup page for detailed information).

  2. Fork the CPython repositoryto your GitHub account and get the source code using:

  3. Build Python, on UNIX and Mac OS use:

    and on Windows use:

    See also more detailed instructions,how to install and build dependencies,and the platform-specific pages for UNIX,Mac OS, and Windows.

  4. Run the tests:

    On most Mac OS X systems, replace ./pythonwith ./python.exe. On Windows, use python.bat. With Python2.7, replace test with test.regrtest.

  5. Create a new branch where your work for the issue will go, e.g.:

    If an issue does not already exist, please create it. Trivial issues (e.g. typo fixes) do notrequire any issue to be created.

  6. Once you fixed the issue, run the tests, run makepatchcheck, and ifeverything is ok, commit.

  7. Push the branch on your fork on GitHub and create a pull request. Include the issue number using bpo-NNNN in thepull request description. For example:

  8. Add a News entry into the Misc/NEWS.d directory as individual file. Thenews entry can be created by using blurb-it,or the blurb tool and its blurbaddcommand. Please read more about blurb in documentation.

Note

First time contributors will need to sign the Contributor LicensingAgreement (CLA) as described in the Licensing section ofthis guide.

Updating Python On Mac

Quick Links¶

Here are some links that you probably will reference frequently whilecontributing to Python:

  • PEPs (Python Enhancement Proposals)

Status of Python branches¶

BranchScheduleStatusFirst releaseEnd-of-lifeRelease manager
masterPEP 619features2021-10-04TBDPablo Galindo Salgado
3.9PEP 596bugfix2020-10-05TBDŁukasz Langa
3.8PEP 569bugfix2019-10-142024-10Łukasz Langa
3.7PEP 537security2018-06-272023-06-27Ned Deily
3.6PEP 494security2016-12-232021-12-23Ned Deily

The master branch is currently the future Python 3.10, and is the onlybranch that accepts new features. The latest release for each Pythonversion can be found on the download page.

Status:

features:new features, bugfixes, and security fixes are accepted.
prerelease:feature fixes, bugfixes, and security fixes are accepted for theupcoming feature release.
bugfix:bugfixes and security fixes are accepted, new binaries are stillreleased. (Also called maintenance mode or stable release)
security:only security fixes are accepted and no more binaries are released,but new source-only versions can be released
end-of-life:release cycle is frozen; no further changes can be pushed to it.

Dates in italic are scheduled and can be adjusted.

By default, the end-of-life is scheduled 5 years after the first release,but can be adjusted by the release manager of each branch. All Python 2versions have reached end-of-life.

See also the Development Cycle page for more information about branches.

Contributing¶

We encourage everyone to contribute to Python and that’s why we have put up thisdeveloper’s guide. If you still have questions after reviewing the material inthis guide, then the Core Python Mentorship group is available to help guide newcontributors through the process.

A number of individuals from the Python community have contributed to a seriesof excellent guides at Open Source Guides.

Core developers and contributors alike will find the following guides useful:

Guide for contributing to Python:

New ContributorsDocumentariansTriagersCore Developers
Getting StartedHelping with DocumentationIssue TrackingHow to Become a Core Developer
Where to Get HelpDocumenting PythonTriaging an IssueDeveloper Log
Lifecycle of a Pull RequestStyle guideHelping Triage IssuesAccepting Pull Requests
Running & Writing TestsreStructuredText PrimerExperts IndexDevelopment Cycle
Fixing “easy” Issues (and Beyond)TranslatingCore Developer Motivations and Affiliations
Following Python’s DevelopmentCore Developers Office Hours
Git Bootcamp and Cheat Sheet

Advanced tasks and topics for once you are comfortable:

  • Fixing issues found by the buildbots
  • Helping out with reviewing open pull requests.See how to review a Pull Request.

It is recommended that the above documents be read as needed. Newcontributors will build understanding of the CPython workflow by reading thesections mentioned in this table. Youcan stop where you feel comfortable and begin contributing immediately withoutreading and understanding these documents all at once. If you do choose to skiparound within the documentation, be aware that it is written assuming precedingdocumentation has been read so you may find it necessary to backtrack to fill inmissing concepts and terminology.

Proposing changes to Python itself¶

Improving Python’s code, documentation and tests are ongoing tasks that arenever going to be “finished”, as Python operates as part of an ever-evolvingsystem of technology. An even more challenging ongoing task than thesenecessary maintenance activities is finding ways to make Python, in the form ofthe standard library and the language definition, an even better tool in adeveloper’s toolkit.

While these kinds of change are much rarer than those described above, they dohappen and that process is also described as part of this guide:

Other Interpreter Implementations¶

This guide is specifically for contributing to the Python reference interpreter,also known as CPython (while most of the standard library is written in Python,the interpreter core is written in C and integrates most easily with the C andC++ ecosystems).

There are other Python implementations, each with a different focus. LikeCPython, they always have more things they would like to do than they havedevelopers to work on them. Some major examples that may be of interest are:

  • PyPy: A Python interpreter focused on high speed (JIT-compiled) operationon major platforms
  • Jython: A Python interpreter focused on good integration with the JavaVirtual Machine (JVM) environment
  • IronPython: A Python interpreter focused on good integration with theCommon Language Runtime (CLR) provided by .NET and Mono
  • Stackless: A Python interpreter focused on providing lightweightmicrothreads while remaining largely compatible with CPython specificextension modules

Key Resources¶

  • Coding style guides
    • PEP 7 (Style Guide for C Code)
    • PEP 8 (Style Guide for Python Code)
  • Issue tracker
    • Meta tracker (issuetracker for the issue tracker)
  • Source code
  • PEPs (Python Enhancement Proposals)

Additional Resources¶

  • Anyone can clone the sources for this guide. SeeHelping with the Developer’s Guide.
  • Help with …
  • Tool support
    • Various tools with configuration files as found in the Misc directory
    • Information about editors and their configurations can be found in thewiki

Code of Conduct¶

Please note that all interactions onPython Software Foundation-supportedinfrastructure is coveredby the PSF Code of Conduct,which includes all infrastructure used in the development of Python itself(e.g. mailing lists, issue trackers, GitHub, etc.).In general this means everyone is expected to be open, considerate, andrespectful of others no matter what their position is within the project.

Full Table of Contents¶

Updating Python Version On Mac

  • 1. Getting Started
    • 1.3. Compile and build
    • 1.4. Install dependencies
    • 1.6. Troubleshoot the build
  • 2. Where to Get Help
  • 3. Lifecycle of a Pull Request
    • 3.3. Step-by-step Guide
    • 3.10. Reviewing
  • 4. Running & Writing Tests
    • 4.1. Running
  • 5. Increase Test Coverage
    • 5.2. Measuring Coverage
  • 6. Helping with Documentation
  • 7. Documenting Python
    • 7.2. Style guide
    • 7.3. reStructuredText Primer
    • 7.4. Additional Markup Constructs
    • 7.5. Building the documentation
    • 7.6. Translating
  • 10. Issue Tracking
    • 10.1. Using the Issue Tracker
    • 10.3. Helping Triage Issues
  • 11. Triaging an Issue
    • 11.2. Becoming a member of the Python triage team
    • 11.3. Fields in the Issue Tracker
  • 12. Following Python’s Development
  • 14. How to Become a Core Developer
    • 14.3. Gaining Commit Privileges
  • 15. Developer Log
  • 16. Accepting Pull Requests
    • 16.3. Working with Git
  • 17. Development Cycle
    • 17.1. Branches
    • 17.2. Stages
    • 17.3. Repository Administration
  • 18. Continuous Integration
  • 19. Adding to the Stdlib
    • 19.2. Adding a new module
  • 20. Changing the Python Language
  • 21. Experts Index
  • 22. gdb Support
  • 23. Exploring CPython’s Internals
  • 24. Changing CPython’s Grammar
  • 25. Design of CPython’s Compiler
  • 26. Design of CPython’s Garbage Collector
    • 26.3. Identifying reference cycles
    • 26.5. Optimization: generations
  • 28. Coverity Scan
    • 28.3. Known limitations
    • 28.5. Workflow
  • 29. Dynamic Analysis with Clang
    • 29.3. Clang/LLVM Setup
    • 29.4. Python Build Setup
  • 30. Running a buildbot worker
    • 30.2. Setting up the buildbot worker
  • 31. Core Developer Motivations and Affiliations
  • 32. Git Bootcamp and Cheat Sheet
  • 33. Appendix: Topics