ubsuny / CP1-24-HW1

Homework template for CP1 in 2024
1 stars 17 forks source link

qiskit not found using codespace with python kernel 3.12.6 #18

Open laserlab opened 2 months ago

laserlab commented 2 months ago

For unclear reasons qiskit is not found if selecting python kernel 3.12.6

import qiskit

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], <a href='vscode-notebook-cell:?execution_count=1&line=1'>line 1</a>
----> <a href='vscode-notebook-cell:?execution_count=1&line=1'>1</a> import qiskit

ModuleNotFoundError: No module named 'qiskit'
laserlab commented 2 months ago

The best way to circumvent the problem for now is to use python kernel 3.9.6

ojha-aditya commented 1 month ago

We could have a look at this https://docs.quantum.ibm.com/api/qiskit/release-notes/0.45

So basically it says that the error could be due to the new changes in the Qiskit packaging structure.

If import qiskit raises an ImportError for you, your environment is in an invalid state, and versions of Qiskit 0.45/0.46 and 1.0 are both reachable, which will result in subtly broken code. You will need to create a new virtual environment, and ensure that only one of the two versions are installed. In particular, if you are intending to install Qiskit 1.0, you must have no packages that depend on qiskit-terra installed; these packages are incompatible with Qiskit 1.0 and must be updated. If you are intending to install Qiskit 0.45 or 0.46, you must ensure that you have nothing attempting to install qiskit>=1.0.

Maybe this is the reason for the above error? Although I am not sure why it works on Python 3.9.6 if that is the case.

laserlab commented 1 month ago

No that’s not it. It’s about where the packages are getting installed. It’s a codespace issue.

SchrodingersStruggle commented 1 month ago

@laserlab Would you be able to go to the terminal in the codespace (I used zsh) any type pip install qiskit to see what happens?

I had the same issue, and I got qiskit working on a code space with python 3.12.6 by manually installing it through the terminal in the codespace and refreshing the window if need be. Also helped get qiskit-aer working too.

laserlab commented 1 month ago

@SchrodingersStruggle That will work but is discouraged since then we don’t all have the same environment. So the goal is to setup a codespace that works without additional manual installs

ojha-aditya commented 1 month ago

For our case it probably doesn't make much of a difference but in a broader sense does changing python kernels for qiskit affect? I am asking since there are some libraries that do not import while using the 3.9 kernels. I remember, having trouble with icecream the day it was discussed in class, last week.

I will put the snippet from my codespace here, trying to figure out how to do that.

jkblc commented 1 month ago

Has this been resolved? I didn't run into the issue so maybe the requirements were changed successfully.