Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qiskit namespace conflicts with Qiskit Terra in Jupyter environment #1580

Closed
kevinsung opened this issue Aug 15, 2022 · 4 comments
Closed

qiskit namespace conflicts with Qiskit Terra in Jupyter environment #1580

kevinsung opened this issue Aug 15, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@kevinsung
Copy link

Informations

  • Qiskit Aer version: 0.10.4
  • Python version: 3.9.7
  • Operating system: RHEL 8.6

What is the current behavior?

qiskit namespace conflicts with Qiskit Terra in Jupyter environment

Steps to reproduce the problem

  1. Create a fresh virtual environment
pipenv shell
pip install --upgrade pip setuptools wheel
  1. Install Qiskit Aer
pip install qiskit-aer
  1. Install Qiskit Terra in editable mode
cd qiskit-terra
pip install -e .
  1. Open a Jupyter notebook in this environment
pip install ipykernel
python -m ipykernel install --user --name tmp
  1. In the Jupyter notebook, importing qiskit doesn't work. For example,
import qiskit
print(qiskit)
<module 'qiskit' (namespace)>
from qiskit import QuantumCircuit
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 from qiskit import QuantumCircuit

ImportError: cannot import name 'QuantumCircuit' from 'qiskit' (unknown location)

What is the expected behavior?

Qiskit should work in the Jupyter notebook. It does work in a shell though.

Suggested solutions

I don't know if this is related but I noticed that installing Qiskit Aer adds files to the virtual environment root where it seems they shouldn't be. For example, before installing Aer the virtual environment root has these contents:

bin
lib
lib64
pyvenv.cfg

After installing Aer, the contents are like this:

bin
cmake
CMakeLists.txt
contrib
lib
lib64
MANIFEST.in
pyproject.toml
pyvenv.cfg
qiskit
README.md
share
src

Most of the extra files seem to be from the Qiskit Aer repository.

@kevinsung kevinsung added the bug Something isn't working label Aug 15, 2022
@mtreinish
Copy link
Member

This is a broader bug in python packaging around namespace packages see Qiskit/qiskit#559. Namespace packaging in python is very error prone and I've been working for a long time on trying to fix this by removing namespace packaging from qiskit, and hopefully once #1526 merges we'll finally be done with using namespace packages for good.

The workaround in the meantime is try not to mix editable mode and standard installs of packages in the shared namespace, but if you must install terra first in editable mode and then try installing aer from pypi second.

As for the stray contents in the venv that's already reported in #1457 and is an upstream bug in scikit-build around the MANIFEST.in file.

@kevinsung
Copy link
Author

kevinsung commented Aug 16, 2022

Thanks @mtreinish . I tried installing both qiskit-terra and qiskit-ibmq-provider in editable mode, but installing the latter still causes the issue.

I also tried installing qiskit-aer in editable mode. The same issue occurs, and what is more, it persists even after uninstalling qiskit-aer. In other words, installing qiskit-aer seems to permanently bork the environment.

@kevinsung
Copy link
Author

Setting the environment variable

SETUPTOOLS_ENABLE_FEATURES="legacy-editable"

works around the issue. Thanks @jakelishman !

@kevinsung
Copy link
Author

I'll close this issue since there is another one already tracking the namespace issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants