# Error occurred while importing pennylane on Colab

**URL:** <https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433>\
**Category:** PennyLane Help\
**Created:** [April 24, 2025, 7:03am UTC](https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433 "2025-04-24T07:03:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BEOMJOONG\_KIM](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/beomjoong_kim/32/3731_2.png) [@BEOMJOONG\_KIM](https://discuss.pennylane.ai/u/BEOMJOONG_KIM)\
**Post date:** [April 24, 2025, 7:03am UTC](https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433/1 "2025-04-24T07:03:21Z")

</div>

Hi everyone, an error occurred while importing pennylane on Google Colab. I’ve tried many things, but the error still occurs.

# Installation of Python 3.8.20

```auto
!apt-get update
!apt-get install python3.8 python3.8-distutils
!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
!wget https://bootstrap.pypa.io/get-pip.py
!python3.8 get-pip.py

```

# Installation of Packages

```auto
!python3.8 -m pip install --upgrade pip
!python3.8 -m pip install tensorflow==2.4.0
!python3.8 -m pip install --force-reinstall pennylane==0.17.0
!python3.8 -m pip install --force-reinstall strawberryfields==0.18.0
!python3.8 -m pip install pennylane-sf==0.16.0
!python3.8 -m pip install numba==0.53.1
!python3.8 -m pip install numpy==1.19.5 matplotlib scikit-learn pandas scikit-image

```

```auto
pip list

```

```auto
import pennylane as qml

```

If you run it, this error will occur.

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/0/015fc29388a5a79e7a2dbd73d2d1b93ca1f8052d.png)

I saw someone else resolve a similar issue with ‘pip install autoray==0.2.5’, so I added

```auto
!python3.8 -m pip install --force-reinstall autoray==0.2.5 

```

at the last of the ‘Installation of Packages’ cell.  
But the problem wasn’t resolved.

Does anyone have an idea how to solve this problem?

---

<div class="post-metadata">

**Author:** ![mchau](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mchau](https://discuss.pennylane.ai/u/mchau)\
**Post date:** [April 24, 2025, 11:48pm UTC](https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433/2 "2025-04-24T23:48:54Z")

</div>

I think you complicated it too much. This worked for me

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/f/f74993d36afb9c37be0ae54f4db7aa713dd8d374.jpeg)  
 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/6/69f2f5f40acd0bb13c2d2a9b72465f3a42243b3f.png)

So I just do `pip install pennylane`, without installing python3.8 inside Colab

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [April 25, 2025, 1:20am UTC](https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433/3 "2025-04-25T01:20:23Z")

</div>

Welcome to the Forum @BEOMJOONG_KIM !

And thanks for jumping in to help @mchau 🙌  
It’s great to see everyone helping each other.

What works for me is `!pip install pennylane` (with the exclamation mark). That should be it!

Also, note that at the moment PennyLane is supported for Python v3.10-3.12, so Python 3.8 might not even work.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![BEOMJOONG\_KIM](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/beomjoong_kim/32/3731_2.png) [@BEOMJOONG\_KIM](https://discuss.pennylane.ai/u/BEOMJOONG_KIM)\
**Post date:** [May 10, 2025, 5:33am UTC](https://discuss.pennylane.ai/t/error-occurred-while-importing-pennylane-on-colab/8433/4 "2025-05-10T05:33:51Z")

</div>

Thank you for replying, @mchau and @CatalinaAlbornoz  
I solved the problem by using

```auto
%%writefile cv_qnn.py
~~ # importing pennylane and other packages
~~ # other codes

```

and using

```auto
!python3.8 cv_qnn.py

```

Thank you!
