I try to install qiskit in Jupyter using the following code in Jupyter notebook:
pip install qiskit
Then I got the following error:
Failed to build cryptography
How should I go about it?
I try to install qiskit in Jupyter using the following code in Jupyter notebook:
pip install qiskit
Then I got the following error:
Failed to build cryptography
How should I go about it?
You can create an environment with python and qiskit in it, then add this environment to Jupyter Notebook. Here is how you do it.
Install Anaconda if you don't already have it install Anaconda , then open Anaconda Prompt in your computer
Create a new environment with Python in it (I name it qiskit_env here). Note: qiskit only works with python version 3.6 or later.
conda create -n qiskit_env python=3.8
Activate this environment
conda activate qiskit_env
Install qiskit in this new environment
pip install qiskit[visualization]
zsh user (which is the default shell on newer versions of macOS), you’ll need to put 'qiskit[visualization]'
in quotes
pip install 'qiskit[visualization]'
Install ipykernal
conda install -c anaconda ipykernel
Add your qiskit environment to jupyter:
python -m ipykernel install --user --name=qiskit_env
Now open your Jupyter Notebook within the activated environment - This is very important. If you open Jupyter outside of this environment, the kernel won't be able to connect.
jupyter notebook
You should be able to create a new notebook with this new environment which has qiskit installed. Later on you can see this qiskit_env
has been added to the kernel list in Jupyter notebook
BTW, if you need to install a new package in the qiskit_env
, you can do the installation in this virtual environment, then install this environment to ipykernel
again.
For example, to add qiskit_optimization
to the qiskit_env
:
Open Anaconda Prompt, and activate the environment
conda activate qiskit_env
Install qiskit_optimization
package in this environment
pip install qiskit[optimization]
zsh user (which is the default shell on newer versions of macOS), you’ll need to put 'qiskit[optimization]'
in quotes
pip install 'qiskit[optimization]'
At last, add your qiskit environment to jupyter again
python -m ipykernel install --user --name=qiskit_env