Python hanging on importing Strawberry Fields

I am having a strange issue on a local machine where importing any part of the installed strawberryfields or thewalrus modules seems to lock up the Python interpreter.

I am using a basic Anaconda environment set up with the following sequence of commands:
conda create --name strawberry python=3.10
conda activate strawberry
pip install strawberryfields

Running conda list yields:

# Name                    Version                   Build  Channel
antlr4-python3-runtime    4.9.2                    pypi_0    pypi
appdirs                   1.4.4                    pypi_0    pypi
bzip2                     1.0.8                he774522_0
ca-certificates           2023.08.22           haa95532_0
certifi                   2023.7.22                pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
cloudpickle               3.0.0                    pypi_0    pypi
colorama                  0.4.6                    pypi_0    pypi
dask                      2023.10.1                pypi_0    pypi
fire                      0.5.0                    pypi_0    pypi
fsspec                    2023.10.0                pypi_0    pypi
idna                      3.4                      pypi_0    pypi
importlib-metadata        6.8.0                    pypi_0    pypi
lark-parser               0.12.0                   pypi_0    pypi
libffi                    3.4.4                hd77b12b_0
llvmlite                  0.41.1                   pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
mpmath                    1.3.0                    pypi_0    pypi
networkx                  3.2.1                    pypi_0    pypi
numba                     0.58.1                   pypi_0    pypi
numpy                     1.26.1                   pypi_0    pypi
openssl                   3.0.12               h2bbff1b_0
packaging                 23.2                     pypi_0    pypi
partd                     1.4.1                    pypi_0    pypi
pip                       23.3            py310haa95532_0
pydantic                  1.10.13                  pypi_0    pypi
python                    3.10.13              he1021f5_0
python-dateutil           2.8.2                    pypi_0    pypi
python-dotenv             1.0.0                    pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
quantum-blackbird         0.5.0                    pypi_0    pypi
quantum-xir               0.2.2                    pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
scipy                     1.11.3                   pypi_0    pypi
setuptools                68.0.0          py310haa95532_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.41.2               h2bbff1b_0
strawberryfields          0.23.0                   pypi_0    pypi
sympy                     1.12                     pypi_0    pypi
termcolor                 2.3.0                    pypi_0    pypi
thewalrus                 0.20.0                   pypi_0    pypi
tk                        8.6.12               h2bbff1b_0
toml                      0.10.2                   pypi_0    pypi
toolz                     0.12.0                   pypi_0    pypi
typing-extensions         4.8.0                    pypi_0    pypi
tzdata                    2023c                h04d1e81_0
urllib3                   2.0.7                    pypi_0    pypi
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.41.2          py310haa95532_0
xanadu-cloud-client       0.3.1                    pypi_0    pypi
xz                        5.4.2                h8cc25b3_0
zipp                      3.17.0                   pypi_0    pypi
zlib                      1.2.13               h8cc25b3_0

All my Python program has to contain is an import statement such as

import strawberryfields

and the interpreter will hang, or at least spend an indeterminate amount of time attempting the import. I have tried leaving the program running for hours without success, while an import numpy statement only takes a fraction of a second.

I was wondering if there was any idea of what could be causing this or if it has been seen to happen in the past.

Hi @tomdodd4598, welcome to the forum!

This is super puzzling, it’s the first time I see this issue.

Can you please share more information about the device you’re using so that we can investigate this issue?

If you run python -m pip install strawberryfields instead of just pip install strawberryfields do you see any difference?

My recommendation in the meantime is to use Google Colab and use ! pip install strawberryfields (with the exclamation mark).

I look forward to seeing your reply!

Thanks very much @CatalinaAlbornoz - the alternate installation method worked! The module now successfully imports within a couple of seconds. The problem with using pip could be related to this similar-sounding issue, so I now know to use python -m pip at all times from now on.

I did use Google colab successfully in the meantime to run the simple scripts I had to run, but this will make future use of the library much easier :slight_smile:

1 Like