DurbanK
DurbanK

Reputation: 23

VS Code Python Interactive Window Fails to Import `rasterio`

I recently updated VS Code to 1.53.2 on Linux (elementaryOS using snap specifically). When trying to run an existing Python script in the Interactive Window, I get the error ModuleNotFoundError: No module named 'rasterio', so obviously it is not finding the rasterio module. I am using a Conda environment, and have confirmed that rasterio is actually installed in the environment, and I have the appropriate environment selected in VS Code.

The module is properly imported when using interactive Python from the terminal, calling the script from the terminal, running the command in a local Jupyter server, and even in Run and Debug Mode in VS Code. I therefore assume the issue is something to do with the Jupyter server used within VS Code. All the other modules I have looked at import just fine, so it seems to be some issue within VS Code specifically with the rasterio package. When using the interactive window, even just running the simple command

import rasterio as rio

fails, again only in VS Code Python Interactive Window and nowhere else. Any thoughts or suggestions or what to do to resolve it, or should I just file an Issue in the VS Code Github repo?

In case it helps, here's the list of installed modules from a basic conda environment (only python3, jupyter, and rasterio installed) where import rasterio fails:

name: scratch
channels:
  - conda-forge
  - defaults
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=1_gnu
  - affine=2.3.0=py_0
  - argon2-cffi=20.1.0=py39h3811e60_2
  - async_generator=1.10=py_0
  - attrs=20.3.0=pyhd3deb0d_0
  - backcall=0.2.0=pyh9f0ad1d_0
  - backports=1.0=py_2
  - backports.functools_lru_cache=1.6.1=py_0
  - bleach=3.3.0=pyh44b312d_0
  - boost-cpp=1.74.0=hc6e9bd1_2
  - bzip2=1.0.8=h7f98852_4
  - c-ares=1.17.1=h36c2ea0_0
  - ca-certificates=2020.12.5=ha878542_0
  - cairo=1.16.0=h7979940_1007
  - certifi=2020.12.5=py39hf3d152e_1
  - cffi=1.14.5=py39he32792d_0
  - cfitsio=3.470=hb418390_7
  - click=7.1.2=pyh9f0ad1d_0
  - click-plugins=1.1.1=py_0
  - cligj=0.7.1=pyhd8ed1ab_0
  - curl=7.71.1=he644dc0_8
  - dbus=1.13.6=hfdff14a_1
  - decorator=4.4.2=py_0
  - defusedxml=0.6.0=py_0
  - entrypoints=0.3=pyhd8ed1ab_1003
  - expat=2.2.10=h9c3ff4c_0
  - fontconfig=2.13.1=hba837de_1004
  - freetype=2.10.4=h0708190_1
  - freexl=1.0.5=h516909a_1002
  - geos=3.9.0=h9c3ff4c_0
  - geotiff=1.6.0=h2b14fbe_4
  - gettext=0.19.8.1=h0b5b191_1005
  - giflib=5.2.1=h36c2ea0_2
  - glib=2.66.7=h9c3ff4c_0
  - glib-tools=2.66.7=h9c3ff4c_0
  - gst-plugins-base=1.18.3=h04508c2_0
  - gstreamer=1.18.3=h3560a44_0
  - hdf4=4.2.13=h10796ff_1004
  - hdf5=1.10.6=nompi_h6a2412b_1114
  - icu=68.1=h58526e2_0
  - importlib-metadata=3.4.0=py39hf3d152e_0
  - importlib_metadata=3.4.0=hd8ed1ab_0
  - ipykernel=5.5.0=py39hef51801_1
  - ipython=7.20.0=py39hef51801_2
  - ipython_genutils=0.2.0=py_1
  - ipywidgets=7.6.3=pyhd3deb0d_0
  - jedi=0.18.0=py39hf3d152e_2
  - jinja2=2.11.3=pyh44b312d_0
  - jpeg=9d=h36c2ea0_0
  - json-c=0.15=h98cffda_0
  - jsonschema=3.2.0=py_2
  - jupyter=1.0.0=py39hf3d152e_6
  - jupyter_client=6.1.11=pyhd8ed1ab_1
  - jupyter_console=6.2.0=py_0
  - jupyter_core=4.7.1=py39hf3d152e_0
  - jupyterlab_pygments=0.1.2=pyh9f0ad1d_0
  - jupyterlab_widgets=1.0.0=pyhd8ed1ab_1
  - kealib=1.4.14=he4dc956_1
  - krb5=1.17.2=h926e7f8_0
  - ld_impl_linux-64=2.35.1=hea4e1c9_2
  - libblas=3.9.0=8_openblas
  - libcblas=3.9.0=8_openblas
  - libclang=11.0.1=default_ha53f305_1
  - libcurl=7.71.1=hcdd3856_8
  - libdap4=3.20.6=hd7c4107_1
  - libedit=3.1.20191231=he28a2e2_2
  - libev=4.33=h516909a_1
  - libevent=2.1.10=hcdb4288_3
  - libffi=3.3=h58526e2_2
  - libgcc-ng=9.3.0=h2828fa1_18
  - libgdal=3.1.4=hbde00c8_6
  - libgfortran-ng=9.3.0=hff62375_18
  - libgfortran5=9.3.0=hff62375_18
  - libglib=2.66.7=h1f3bc88_0
  - libgomp=9.3.0=h2828fa1_18
  - libiconv=1.16=h516909a_0
  - libkml=1.3.0=h02e6976_1012
  - liblapack=3.9.0=8_openblas
  - libllvm11=11.0.1=hf817b99_0
  - libnetcdf=4.7.4=nompi_h56d31a8_107
  - libnghttp2=1.43.0=h812cca2_0
  - libopenblas=0.3.12=pthreads_h4812303_1
  - libpng=1.6.37=h21135ba_2
  - libpq=13.1=hfd2b0eb_1
  - librttopo=1.1.0=hccdd1c9_5
  - libsodium=1.0.18=h36c2ea0_1
  - libspatialite=5.0.1=h04c9dda_2
  - libssh2=1.9.0=hab1572f_5
  - libstdcxx-ng=9.3.0=h6de172a_18
  - libtiff=4.2.0=hdc55705_0
  - libuuid=2.32.1=h7f98852_1000
  - libwebp-base=1.2.0=h7f98852_0
  - libxcb=1.13=h7f98852_1003
  - libxkbcommon=1.0.3=he3ba5ed_0
  - libxml2=2.9.10=h72842e0_3
  - lz4-c=1.9.3=h9c3ff4c_0
  - markupsafe=1.1.1=py39h3811e60_3
  - mistune=0.8.4=py39h3811e60_1003
  - mysql-common=8.0.23=ha770c72_1
  - mysql-libs=8.0.23=h935591d_1
  - nbclient=0.5.2=pyhd8ed1ab_0
  - nbconvert=6.0.7=py39hf3d152e_3
  - nbformat=5.1.2=pyhd8ed1ab_1
  - ncurses=6.2=h58526e2_4
  - nest-asyncio=1.4.3=pyhd8ed1ab_0
  - notebook=6.2.0=py39hf3d152e_0
  - nspr=4.29=h9c3ff4c_1
  - nss=3.62=hb5efdd6_0
  - numpy=1.20.1=py39hdbf815f_0
  - openjpeg=2.4.0=hf7af979_0
  - openssl=1.1.1j=h7f98852_0
  - packaging=20.9=pyh44b312d_0
  - pandoc=2.11.4=h7f98852_0
  - pandocfilters=1.4.2=py_1
  - parso=0.8.1=pyhd8ed1ab_0
  - pcre=8.44=he1b5a44_0
  - pexpect=4.8.0=pyh9f0ad1d_2
  - pickleshare=0.7.5=py_1003
  - pip=21.0.1=pyhd8ed1ab_0
  - pixman=0.40.0=h36c2ea0_0
  - poppler=0.89.0=h2de54a5_5
  - poppler-data=0.4.10=0
  - postgresql=13.1=h6303168_1
  - proj=7.2.0=h277dcde_2
  - prometheus_client=0.9.0=pyhd3deb0d_0
  - prompt-toolkit=3.0.16=pyha770c72_0
  - prompt_toolkit=3.0.16=hd8ed1ab_0
  - pthread-stubs=0.4=h36c2ea0_1001
  - ptyprocess=0.7.0=pyhd3deb0d_0
  - pycparser=2.20=pyh9f0ad1d_2
  - pygments=2.8.0=pyhd8ed1ab_0
  - pyparsing=2.4.7=pyh9f0ad1d_0
  - pyqt=5.12.3=py39hf3d152e_7
  - pyqt-impl=5.12.3=py39h0fcd23e_7
  - pyqt5-sip=4.19.18=py39he80948d_7
  - pyqtchart=5.12=py39h0fcd23e_7
  - pyqtwebengine=5.12.1=py39h0fcd23e_7
  - pyrsistent=0.17.3=py39h3811e60_2
  - python=3.9.2=hffdb5ce_0_cpython
  - python-dateutil=2.8.1=py_0
  - python_abi=3.9=1_cp39
  - pyzmq=22.0.3=py39hea8fd45_0
  - qt=5.12.9=hda022c4_4
  - qtconsole=5.0.2=pyhd8ed1ab_0
  - qtpy=1.9.0=py_0
  - rasterio=1.2.0=py39hb73aa6c_0
  - readline=8.0=he28a2e2_2
  - send2trash=1.5.0=py_0
  - setuptools=49.6.0=py39hf3d152e_3
  - six=1.15.0=pyh9f0ad1d_0
  - snuggs=1.4.7=py_0
  - sqlite=3.34.0=h74cdb3f_0
  - terminado=0.9.2=py39hf3d152e_0
  - testpath=0.4.4=py_0
  - tiledb=2.2.4=hb9a9e87_0
  - tk=8.6.10=h21135ba_1
  - tornado=6.1=py39h3811e60_1
  - traitlets=5.0.5=py_0
  - tzcode=2021a=h7f98852_0
  - tzdata=2021a=he74cb21_0
  - wcwidth=0.2.5=pyh9f0ad1d_2
  - webencodings=0.5.1=py_1
  - wheel=0.36.2=pyhd3deb0d_0
  - widgetsnbextension=3.5.1=py39hf3d152e_4
  - xerces-c=3.2.3=h9d8b166_2
  - xorg-kbproto=1.0.7=h7f98852_1002
  - xorg-libice=1.0.10=h516909a_0
  - xorg-libsm=1.2.3=h84519dc_1000
  - xorg-libx11=1.6.12=h516909a_0
  - xorg-libxau=1.0.9=h7f98852_0
  - xorg-libxdmcp=1.1.3=h7f98852_0
  - xorg-libxext=1.3.4=h516909a_0
  - xorg-libxrender=0.9.10=h516909a_1002
  - xorg-renderproto=0.11.1=h14c3975_1002
  - xorg-xextproto=7.3.0=h7f98852_1002
  - xorg-xproto=7.0.31=h7f98852_1007
  - xz=5.2.5=h516909a_1
  - zeromq=4.3.4=h9c3ff4c_0
  - zipp=3.4.0=py_0
  - zlib=1.2.11=h516909a_1010
  - zstd=1.4.8=ha95c52a_1
prefix: /home/durbank/miniconda3/envs/scratch

Upvotes: 0

Views: 921

Answers (1)

DurbanK
DurbanK

Reputation: 23

The issue apparently lies with a bug in VS Code itself, as seen in this Issue, where the wrong environment is loaded when launching a Python Interactive Window. I'll update this answer when the issue is resolved.

Upvotes: 1

Related Questions