βββNot all packages are supported in Python cells, but many are. You can import a package in a Python cell by importing it as usual. If that doesn't work, then there are some other options you can try.
Step 1: Use micropip
Micropip is a library for installing Python packages, and is used like:
import micropip
await micropip.install('my_package_name')
If this step doesn't succeed, the cause might be:
The package contains non-Python native extensions, which need to be handled specially. Many popular packages have already been compiled to work in a web browser, but if not the process is quite tricky even for Python experts - see the instructions here. In many cases, it will not be possible to support this package. To check whether or not a given package uses native extensions, follow the steps below.
The package depends on other packages with incompatible versions. In this case it is often possible to install the package by using an older version. Follow the steps below
To determine if your package is supported, you can try following these steps:
Step 2: Find the package on PyPI.
You can use the built-in search function, or try a search engine query for "<package name> PyPi". An example page for a package looks like this:
Step 3: Find the.whl file for the package
Click the Download files link, and look under the Build Distribution list for a file name that contains none-any
:
If the filename ends with this, it means that the package is pure Python, and it should be possible to load it in Count.
If you can't find a .whl
file that ends with none-any
, then it is likely that the package contains non-Python extensions, and will need to be compiled to work in the browser.
Step 4: Load the .whl
file in Count
Copy the link to the .whl
file (right-click > Copy link address), and import it in Count using micropip:
# This function avoids using an import statement to import the package, which is useful
# if you want to make sure that Count doesn't try to automatically import the latest
# version of the package.
async def import_package(url: str, name: str):
import micropip
await micropip.install('setuptools')
from importlib import import_module
await micropip.install(url)
return import_module(name)
airtable = await import_package(
'https://files.pythonhosted.org/packages/ec/2b/e5885493796ae222eac6d15ffab093cce8fe63bf10ee920ac205fa65e279/airtable-0.4.8-py2.py3-none-any.whl',
'airtable'
)
Step 5 (optional): Install an older package version
If the latest version of a package can't be installed, sometimes an earlier version can be. To find older package versions, click the Release history link and choose an older version. Then, follow steps 3 and 4 to try an older .whl
file.
---
For more information on Python in Count, check out our docs.