Working with Python Packages
Python Online makes using your favorite libraries incredibly simple. We automatically detect and install supported Python packages for you, so you can focus on writing code without worrying about manual installations.
Automatic Package Installation
There is no package manager or install button. The system is designed to be seamless:
- Write Your Code:
Simply use the
import
statement in your code as you normally would.For example:
import numpy as np
orfrom pandas import DataFrame
. - Click "Run":
When you run your code, our compiler analyzes it.
It automatically detects which supported packages you're trying to use.
The necessary packages are downloaded and installed for you in the background.
- See the Magic!:
Your code then executes in the fully prepared environment.
Example: The following code will work instantly. The compiler will see import numpy
and handle the installation automatically before running the script.
import numpy as np
array = np.array([1, 2, 3])
print(f"NumPy array created: {array}")
Plotting Libraries: Matplotlib & Altair
Our compiler is smart enough to handle plotting libraries in the way you'd intuitively expect.
- Matplotlib: Just use
plt.show()
like you always would. Your static plot will appear directly in the output area. - Altair: Simply call
chart.show()
. Your interactive chart will be rendered for you.
Example (Matplotlib):
import matplotlib.pyplot as plt
plt.plot([10, 20, 5, 40])
plt.ylabel('some numbers')
plt.show()
Supported Packages & Compatibility
This tool runs on Pyodide, which brings Python to the web browser. This means there is a curated list of packages that have been specially compiled to work in this environment. Any package not on this list is considered unsupported.
- The compiler will automatically check if the packages you
import
are on the supported list. - You can see the full, official list of packages supported by our current environment (Pyodide v0.26.1) on the Pyodide documentation site.
Common Errors
- Unsupported Package:
If you try to import a package that is not on the official list, the compiler will stop and notify you.
Example error for an unsupported package 'torch':
Error: The following package(s) are not supported: torch
- "Module Not Found" Despite Being Supported:
This can happen if you use an incorrect import name. For example, the package is named
scikit-learn
, but you must import it withimport sklearn
. Our system handles the most common cases (likePIL
forpillow
), but always double-check the library's official import conventions.
List All Available Packages
You can see every package that is pre-loaded or that you have imported during your session by running the following code:
from importlib.metadata import distributions
packages = [f"{dist.metadata['Name']}: {dist.version}" for dist in distributions()]
packages.sort()
for pkg in packages:
print(pkg)
With Python Online's smart package handling, you can leverage the power of Python’s extensive library ecosystem with zero setup, directly from your browser. Happy coding! 📦