Hi again,
I am finally able to fix the instalation isssue on colab.
Kwant installation in Google Colab works, but the main issue is not Kwant
itself — it is the Colab environment architecture. In my case, I initially
tried installing Kwant using Conda (condacolab + conda-forge). However,
even though installation appeared successful, import kwant failed because
the Colab notebook kernel was still running a different Python interpreter (
/usr/bin/python3.real) instead of the Conda Python environment.
After investigation, the real issue turned out to be a *Python environment
mismatch combined with dependency incompatibility*.
Key issues encountered
1. *Conda environment mismatch*
- Kwant was installed inside Conda (/usr/local), but the notebook
kernel did not use that environment.
- As a result, Python could not see the installed package.
2. *Binary build failure with default scientific stack*
- Installing Kwant via pip initially failed due to compilation issues
with NumPy 2.x and SciPy versions shipped in Colab.
3. *Correct fix required pinning dependencies*
- Downgrading NumPy and SciPy to compatible versions resolved the
build issue.
The installation only worked reliably after using the following steps:
pip install numpy==1.26.4 scipy==1.11.4
pip install tinyarray
pip install --no-cache-dir kwant
After this, Kwant compiled successfully and imported without errors.
best
Adel
Le mer. 10 juin 2026 à 21:23, Adel Belayadi <[email protected]> a écrit :
> Hello kwant users,
> It has been quite some time since I last saw activity on this
> forum—perhaps AI assistants have become everyone's first stop for
> troubleshooting! Nevertheless, I am hoping to get some advice from the
> community on an issue I have encountered.
>
> I have a Gemini Pro subscription and frequently use Google Colab, which
> now has Gemini integrated directly into the notebook environment. One of
> the reasons I would like to use Kwant in Colab is to take advantage of the
> built-in AI assistance while developing and analyzing Kwant-based
> simulations.
> However, I am experiencing difficulties using Kwant in Google Colab. Kwant
> appears to install successfully, and the installation is recognized by the
> environment, but importing Kwant from within a notebook cell results in a
> ModuleNotFoundError.
>
> The environment is Google Colab with Python 3.11.11 and Kwant 1.5.0
> installed from conda-forge. During the process, I also encountered a Python
> version pinning conflict involving Python 3.12 versus the installed Python
> 3.11.11, which may or may not be related.
>
> What is confusing is that Kwant seems to be present and accessible at the
> environment level, yet it remains unavailable from within the notebook
> kernel itself. This suggests a possible mismatch between the environment
> where Kwant is installed and the interpreter used by the notebook.
> Has anyone encountered a similar issue when using Kwant with Google Colab?
> Is there a known compatibility problem with recent Colab environments, or a
> recommended way to ensure that the notebook kernel is using the correct
> environment?
>
> Any guidance would be greatly appreciated.
>
> Best
> Adel
>