Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

** NOTE ** This project is no longer actively developed!

Can I Use Python 3?

This script takes in a set of dependencies and then figures out which of them are holding you up from porting to Python 3.

Command-line/Web Usage

You can specify your dependencies in multiple ways:

caniusepython3 -r requirements.txt test-requirement.txt
caniusepython3 -m PKG-INFO
caniusepython3 -p numpy scipy ipython
# If your project's setup.py uses setuptools
# (note that setup_requires can't be checked) ...
python setup.py caniusepython3

The output of the script will tell you how many (implicit) dependencies you need to transition to Python 3 in order to allow you to make the same transition. It will also list what projects have no dependencies blocking their transition so you can ask them to start a port to Python 3.

If you prefer a web interface you can use https://caniusepython3.com by Jannis Leidel.

Integrating With Your Tests

If you want to check for Python 3 availability as part of your tests, you can use caniusepython3.check():

def check(requirements_paths=[], metadata=[], projects=[]):
    """Return True if all of the specified dependencies have been ported to Python 3.

    The requirements_paths argument takes a sequence of file paths to
    requirements files. The 'metadata' argument takes a sequence of strings
    representing metadata. The 'projects' argument takes a sequence of project
    names.

    Any project that is not listed on PyPI will be considered ported.
    """

You can then integrate it into your tests like so:

import unittest
import caniusepython3

class DependenciesOnPython3(unittest.TestCase):
  def test_dependencies(self):
    # Will begin to fail when dependencies are no longer blocking you
    # from using Python 3.
    self.assertFalse(caniusepython3.check(projects=['ipython']))

For the change log, how to tell if a project has been ported, as well as help on how to port a project, please see the project website.

Extending pylint --py3k

In Pylint 1.4, a --py3k option was added to the linting tool to turn on checks for Python 2/3 incompatibilities (all other checks are turned off). While great, those checks are a little conservative in order to always be accurate. To fill out those checks with stricter – albeit potentially inaccurate – checkers, caniusepython3.pylint_checker exists. On top of everything pylint --py3k already checks for, it adds checks for:

  1. Uses of open() (in Python3, open() is actually io.open())

  2. String literals that do not have a b/u prefix or from __future__ import unicode_literals

If you wish to use the checker with Pylint, you can add it to your Pylint configuration file, e.g.:

[MASTER]
load-plugins=caniusepython3.pylint_checker

Secret, bonus feature

If you would like to use a different name for the script and setuptools command then set the environment variable CIU_ALT_NAME to what you would like the alternative name to be. Reddit suggests icanhazpython3.

Release files for caniusepython3 7.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caniusepython3 7.3.0
File Size Uploaded
caniusepython3-7.3.0.tar.gz 25.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for caniusepython3 7.3.0
File Interpreter ABI Platform
caniusepython3-7.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 54.9 kB

Release files / caniusepython3-7.3.0.tar.gz

Download URL caniusepython3-7.3.0.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
58cb3b3643530bc955d3dc5fe49385ccd1f0d2677bf1d9b159814c0f5e677562
BLAKE2b-256 checksum
How to use checksums
69b2d1cf4440751eaa1a33bd6dbf8e5120aecd49a662ae9568c4203282d6af79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

Release files / caniusepython3-7.3.0-py2.py3-none-any.whl

Download URL caniusepython3-7.3.0-py2.py3-none-any.whl
Size 29.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
003d59386905809b7d83a7f093643f11f3003d1766560e02f61f2aa8d8c63d9e
BLAKE2b-256 checksum
How to use checksums
c903dd95687a4b1eb0c3396a3ab0cdd94cd784d79285b6eec83d01cdc7d8e823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page