0

That's my first question here, but that won't be the first time Stack Overflow save me !

I am using conda on a windows10 machine and created my env with tensorflow 2.0 When I tried to add pydicom (v1.4 from condaforge) there was an issue with tensorflow 2.0 : conda wanted to downgrade tf to an 1.x version.

Today I tried to create a new env with :

conda create -n DICOM_TF
conda install pydicom=1.3
conda update python=3.7
conda install pydot
conda install nibabel
conda install pytables
conda install -c https://conda.anaconda.org/simpleitk SimpleITK
conda install nipype
conda install pandas
conda install tensorflow=2.1

Pydicom is installed, I tried the 1.3 and the 1.4 versions of pydicom. I can find it with an anaconda prompt

(base) PS C:\Users\alexa> conda activate DICOM_TF
(DICOM_TF) PS C:\Users\alexa> conda list
# packages in environment at C:\Users\alexa\.conda\envs\DICOM_TF:
#
# Name                    Version                   Build  Channel
_tflow_select             2.2.0                     eigen
absl-py                   0.9.0                    py37_0
asn1crypto                1.3.0                    py37_0
astor                     0.8.0                    py37_0
blas                      1.0                         mkl
blinker                   1.4                      py37_0
blosc                     1.16.3               h7bd577a_0
bzip2                     1.0.8                he774522_0
ca-certificates           2020.1.1                      0
cachetools                3.1.1                      py_0
certifi                   2019.11.28               py37_0
cffi                      1.14.0           py37h7a1dbc1_0
chardet                   3.0.4                 py37_1003
click                     7.0                      py37_0
cryptography              2.8              py37h7a1dbc1_0
cycler                    0.10.0                   py37_0
decorator                 4.4.1                      py_0
etelemetry                0.1.2                      py_1    conda-forge
filelock                  3.0.12                     py_0
freetype                  2.9.1                ha9979f8_1
gast                      0.2.2                    py37_0
google-auth               1.11.2                     py_0
google-auth-oauthlib      0.4.1                      py_2
google-pasta              0.1.8                      py_0
graphviz                  2.38                 hfd603c8_2
grpcio                    1.27.2           py37h351948d_0
h5py                      2.10.0           py37h5e291fa_0
hdf5                      1.10.4               h7ebc959_0
html5lib                  1.0.1                    py37_0
icc_rt                    2019.0.0             h0cc432a_1
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py37_0
intel-openmp              2020.0                      166
isodate                   0.6.0                      py_1
joblib                    0.14.1                     py_0
jpeg                      9b                   hb83a4c4_2
keepalive                 0.5                        py_1    conda-forge
keras-applications        1.0.8                      py_0
keras-preprocessing       1.1.0                      py_1
kiwisolver                1.1.0            py37ha925a31_0
libiconv                  1.15                 h1df5818_7
libpng                    1.6.37               h2a8f88b_0
libprotobuf               3.11.4               h7bd577a_0
libtiff                   4.1.0                h56a325e_0
libxml2                   2.9.9                h464c3ec_0
libxslt                   1.1.33               h579f668_0
lxml                      4.5.0            py37h1350720_0
lz4-c                     1.8.1.2              h2fa13f4_0
lzo                       2.10                 h6df0209_2
markdown                  3.1.1                    py37_0
matplotlib                3.1.3                    py37_0
matplotlib-base           3.1.3            py37h64f37c6_0
mkl                       2020.0                      166
mkl-service               2.3.0            py37hb782905_0
mkl_fft                   1.0.15           py37h14836fe_0
mkl_random                1.1.0            py37h675688f_0
mock                      4.0.1                      py_0
networkx                  2.4                        py_0
neurdflib                 5.0.1                      py_0    conda-forge
nibabel                   3.0.1                      py_0    conda-forge
nilearn                   0.6.1              pyh5ca1d4c_1    conda-forge
nipype                    1.4.2                    py37_0    conda-forge
numexpr                   2.7.1            py37h25d0782_0
numpy                     1.18.1           py37h93ca92e_0
numpy-base                1.18.1           py37hc3f5095_1
oauthlib                  3.1.0                      py_0
olefile                   0.46                     py37_0
openssl                   1.1.1d               he774522_4
opt_einsum                3.1.0                      py_0
packaging                 20.1                       py_0
pandas                    1.0.1            py37h47e9c7a_0
pillow                    7.0.0            py37hcc1f983_0
pip                       20.0.2                   py37_1
protobuf                  3.11.4           py37h33f27b4_0
prov                      1.5.3                      py_1    conda-forge
psutil                    5.6.7            py37he774522_0
pyasn1                    0.4.8                      py_0
pyasn1-modules            0.2.7                      py_0
pycparser                 2.19                     py37_0
pydicom                   1.3.0                      py_0    conda-forge
pydot                     1.4.1                    py37_0
pydotplus                 2.0.2                    py37_1
pyjwt                     1.7.1                    py37_0
pyopenssl                 19.1.0                   py37_0
pyparsing                 2.4.6                      py_0
pyqt                      5.9.2            py37h6538335_2
pyreadline                2.1                      py37_1
pysocks                   1.7.1                    py37_0
pytables                  3.6.1            py37h1da0976_0
python                    3.7.6                h60c2a47_2
python-dateutil           2.8.1                      py_0
pytz                      2019.3                     py_0
pywin32                   227              py37he774522_1
qt                        5.9.7            vc14h73c81de_0
rdflib                    4.2.2                 py37_1000    conda-forge
requests                  2.22.0                   py37_1
requests-oauthlib         1.3.0                      py_0
rsa                       4.0                        py_0
scikit-learn              0.22.1           py37h6288b17_0
scipy                     1.4.1            py37h9439919_0
setuptools                45.2.0                   py37_0
simpleitk                 1.2.4            py37ha925a31_0    simpleitk
simplejson                3.17.0           py37he774522_0
sip                       4.19.8           py37h6538335_0
six                       1.14.0                   py37_0
snappy                    1.1.7                h777316e_3
sparqlwrapper             1.8.2                 py37_1000    conda-forge
sqlite                    3.31.1               he774522_0
tensorboard               2.1.0                     py3_0
tensorflow                2.1.0           eigen_py37hd727fc0_0
tensorflow-base           2.1.0           eigen_py37h49b2757_0
tensorflow-estimator      2.1.0              pyhd54b08b_0
termcolor                 1.1.0                    py37_1
tk                        8.6.8                hfa6e2cd_0
tornado                   6.0.3            py37he774522_3
traits                    5.2.0            py37he774522_0
urllib3                   1.25.8                   py37_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_1
webencodings              0.5.1                    py37_1
werkzeug                  0.14.1                   py37_0
wheel                     0.34.2                   py37_0
win_inet_pton             1.1.0                    py37_0
wincertstore              0.2                      py37_0
wrapt                     1.11.2           py37he774522_0
xz                        5.2.4                h2fa13f4_4
zlib                      1.2.11               h62dcd97_3
zstd                      1.3.7                h508b16e_0
(DICOM_TF) PS C:\Users\alexa>

But when I run some code in jupyter notebook I can't import pydicom (neither dicom which was the name for pydicom versions <1.0)

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-aa8631cee69b> in <module>
      1 import matplotlib.pyplot as plt
      2 import numpy as np
----> 3 import pydicom as dicom
      4 import os
      5 import pandas

ModuleNotFoundError: No module named 'pydicom'

But the module is installed and works if I open python in the anaconda prompt :

(DICOM_TF) PS C:\Users\alexa> python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydicom
>>> exemple= pydicom.dcmread(r"J:\ExportODIASP1\Optima\Export_2020-01-31_15-38-39\10000000\10000001\10000086\100000A6",force =True,specific_tags =["ImagePositionPatient"])
>>> if (0x20, 0x32) in exemple:
...             position1 = exemple["ImagePositionPatient"].value
...
>>> print(position1)
['-165.629', '-379.095', '88.125']
>>>

DO you have any solution to use pydicom and tf2.1 in the same environment ?

Thank you for your help :) Have a nice day, Alex

Alex Nérot
  • 1
  • 1
  • 2
  • Actually "import pydicom" works well when unsing an other environment without tensorflow. – Alex Nérot Feb 20 '20 at 22:23
  • 1
    What do you get with the `DICOM_TF` env if you start the Python interpreter and `import pydicom`? Also, is that the entire traceback? – scaramallion Feb 21 '20 at 01:27
  • This is the traceback using DICOM_TF env. Actually pydicom is installed as you can see with the conda list call. – Alex Nérot Feb 21 '20 at 09:33
  • This code works well using another env without tensorflow – Alex Nérot Feb 21 '20 at 09:33
  • this might be a conda issue. I have no problems using pydicom 1.4.1 alongside tensorflow 2.1.0 but I have installed it with pip – 53RT Feb 21 '20 at 09:45
  • When you run the jupyter notebook make sure the kernel you're running is actually using the correct conda environment. There are many ways you can check this, such as in the notebook print `sys.executable` and make sure it's the correct Python interpreter in the path of your environment. Likewise with `sys.path`. – Iguananaut Feb 21 '20 at 10:40

2 Answers2

1

I created the following environment.yml and it worked for me:

name: tensorflow
channels:
    - anaconda
    - conda-forge
dependencies:
    - python=3.7
    - tensorflow>=2.1.0
    - pydicom>=1.4.0
    - notebook
    - jupyter_console

you might be able to add other dependencies as needed.

You can create an environment from this environment.yml by running:

$ conda env create

in the same directory as the environment.yml, or specify its path with the -f flag. By default it will take the environment name from environment.yml as well.

Then activate the environment:

$ conda activate tensorflow

I installed jupyter_console which is like the command-line equivalent of the Jupyter Notebook. Anything that works in the console should work the same in the notebook, since in both cases it's connecting to the same underlying Python kernel:

$ jupyter console  # runs the python kernel by default
Jupyter console 6.1.0

Python 3.7.6 (default, Jan  8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import tensorflow

In [2]: tensorflow.__version__
Out[2]: '2.1.0'

In [3]: import pydicom

In [4]: pydicom.__version__
Out[4]: '1.4.1'

Update: Just to be sure, I updated my environment.yml to add the other packages you mentioned in your question:

name: tensorflow
channels:
    - anaconda
    - conda-forge
    - simpleitk
dependencies:
    - python=3.7
    - tensorflow>=2.1.0
    - pydicom>=1.4.0
    - notebook
    - jupyter_console
    - pydot
    - nibabel
    - pytables
    - simpleitk
    - nipype
    - pandas

Then ran conda env update to update the package selections in the environment. Confirmed the same results w.r.t. tensorflow and pydicom:

$ jupyter console
Jupyter console 6.1.0

Python 3.7.6 (default, Jan  8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import tensorflow

In [2]: tensorflow.__version__
Out[2]: '2.1.0'

In [3]: import pydicom

In [4]: pydicom.__version__
Out[4]: '1.4.1'

For what it's worth, here's the full environment after installing this environment.yml:

$ conda list
# packages in environment at /path/to/conda/envs/tensorflow:
#
# Name                    Version                   Build  Channel
_tflow_select             2.3.0                       mkl    anaconda
absl-py                   0.9.0                    py37_0    anaconda
asn1crypto                1.3.0                    py37_0    anaconda
astor                     0.8.0                    py37_0    anaconda
attrs                     19.3.0                     py_0    anaconda
backcall                  0.1.0                    py37_0    anaconda
blas                      1.0                         mkl    anaconda
bleach                    3.1.0                    py37_0    anaconda
blinker                   1.4                      py37_0    anaconda
blosc                     1.17.1               he1b5a44_0    conda-forge
bzip2                     1.0.8                h7b6447c_0    anaconda
c-ares                    1.15.0            h7b6447c_1001    anaconda
ca-certificates           2020.1.1                      0    anaconda
cachetools                3.1.1                      py_0    anaconda
cairo                     1.14.12              h8948797_3    anaconda
certifi                   2019.11.28               py37_0    anaconda
cffi                      1.14.0           py37h2e261b9_0    anaconda
chardet                   3.0.4                 py37_1003    anaconda
click                     7.0                      py37_0    anaconda
cryptography              2.8              py37h1ba5d50_0    anaconda
cycler                    0.10.0                   py37_0    anaconda
dbus                      1.13.12              h746ee38_0    anaconda
decorator                 4.4.1                      py_0    anaconda
defusedxml                0.6.0                      py_0    anaconda
entrypoints               0.3                      py37_0    anaconda
etelemetry                0.1.2                      py_1    conda-forge
expat                     2.2.6                he6710b0_0    anaconda
filelock                  3.0.12                     py_0    anaconda
fontconfig                2.13.0               h9420a91_0    anaconda
freetype                  2.9.1                h8a8886c_1    anaconda
fribidi                   1.0.5                h7b6447c_0    anaconda
gast                      0.2.2                    py37_0    anaconda
glib                      2.56.2               hd408876_0    anaconda
gmp                       6.1.2                hb3b607b_0    anaconda
google-auth               1.11.2                     py_0    anaconda
google-auth-oauthlib      0.4.1                      py_2    anaconda
google-pasta              0.1.8                      py_0    anaconda
graphite2                 1.3.13               h23475e2_0    anaconda
graphviz                  2.40.1               h21bd128_2    anaconda
grpcio                    1.27.2           py37hf8bcb03_0    anaconda
gst-plugins-base          1.14.0               hbbd80ab_1    anaconda
gstreamer                 1.14.0               hb453b48_1    anaconda
h5py                      2.10.0           py37h7918eee_0    anaconda
harfbuzz                  1.8.8                hffaf4a1_0    anaconda
hdf5                      1.10.4               hb1b8bf9_0    anaconda
html5lib                  1.0.1                    py37_0    anaconda
icu                       58.2                 h211956c_0    anaconda
idna                      2.8                      py37_0    anaconda
importlib_metadata        1.5.0                    py37_0    anaconda
intel-openmp              2020.0                      166    anaconda
ipykernel                 5.1.4            py37h39e3cac_0    anaconda
ipython                   7.12.0           py37h5ca1d4c_0    anaconda
ipython_genutils          0.2.0                    py37_0    anaconda
isodate                   0.6.0                      py_1    anaconda
jedi                      0.16.0                   py37_0    anaconda
jinja2                    2.11.1                     py_0    anaconda
jpeg                      9b                   habf39ab_1    anaconda
jsonschema                3.2.0                    py37_0    anaconda
jupyter_client            5.3.4                    py37_0    anaconda
jupyter_console           6.1.0                      py_0    anaconda
jupyter_core              4.6.1                    py37_0    anaconda
keepalive                 0.5                        py_1    conda-forge
keras-applications        1.0.8                      py_0    anaconda
keras-preprocessing       1.1.0                      py_1    anaconda
kiwisolver                1.1.0            py37he6710b0_0    anaconda
ld_impl_linux-64          2.33.1               h53a641e_7    anaconda
libedit                   3.1.20181209         hc058e9b_0    anaconda
libffi                    3.2.1                h4deb6c0_3    anaconda
libgcc-ng                 9.1.0                hdf63c60_0    anaconda
libgfortran-ng            7.3.0                hdf63c60_0    anaconda
libpng                    1.6.37               hbc83047_0    anaconda
libprotobuf               3.11.4               hd408876_0    anaconda
libsodium                 1.0.16               h1bed415_0    anaconda
libstdcxx-ng              9.1.0                hdf63c60_0    anaconda
libtiff                   4.1.0                h2733197_0    anaconda
libuuid                   1.0.3                h1bed415_2    anaconda
libxcb                    1.13                 h1bed415_1    anaconda
libxml2                   2.9.9                hea5a465_1    anaconda
libxslt                   1.1.33               h7d1a2b0_0    anaconda
lxml                      4.5.0            py37hefd8a0e_0    anaconda
lzo                       2.10                 h1bfc0ba_1    anaconda
markdown                  3.1.1                    py37_0    anaconda
markupsafe                1.1.1            py37h7b6447c_0    anaconda
matplotlib                3.1.3                    py37_0    anaconda
matplotlib-base           3.1.3            py37hef1b27d_0    anaconda
mistune                   0.8.4            py37h7b6447c_0    anaconda
mkl                       2019.5                      281    anaconda
mkl-service               2.3.0            py37he904b0f_0    anaconda
mkl_fft                   1.0.15           py37ha843d7b_0    anaconda
mkl_random                1.1.0            py37hd6b4f25_0    anaconda
mock                      4.0.1                      py_0    anaconda
nbconvert                 5.6.1                    py37_0    anaconda
nbformat                  5.0.4                      py_0    anaconda
ncurses                   6.1                  he6710b0_1    anaconda
networkx                  2.4                        py_0    anaconda
neurdflib                 5.0.1                      py_0    conda-forge
nibabel                   3.0.1                      py_0    conda-forge
nipype                    1.4.2                    py37_0    conda-forge
notebook                  6.0.3                    py37_0    anaconda
numexpr                   2.7.1            py37h423224d_0    anaconda
numpy                     1.18.1           py37h4f9e942_0    anaconda
numpy-base                1.18.1           py37hde5b4d6_1    anaconda
oauthlib                  3.1.0                      py_0    anaconda
openssl                   1.1.1                h7b6447c_0    anaconda
opt_einsum                3.1.0                      py_0    anaconda
packaging                 20.1                       py_0    anaconda
pandas                    1.0.1            py37h0573a6f_0    anaconda
pandoc                    2.2.3.2                       0    anaconda
pandocfilters             1.4.2                    py37_1    anaconda
pango                     1.42.4               h049681c_0    anaconda
parso                     0.6.1                      py_0    anaconda
pcre                      8.43                 he6710b0_0    anaconda
pexpect                   4.8.0                    py37_0    anaconda
pickleshare               0.7.5                    py37_0    anaconda
pip                       20.0.2                   py37_1    anaconda
pixman                    0.38.0               h7b6447c_0    anaconda
prometheus_client         0.7.1                      py_0    anaconda
prompt_toolkit            3.0.3                      py_0    anaconda
protobuf                  3.11.4           py37he6710b0_0    anaconda
prov                      1.5.3                      py_1    conda-forge
psutil                    5.6.7            py37h7b6447c_0    anaconda
ptyprocess                0.6.0                    py37_0    anaconda
pyasn1                    0.4.8                      py_0    anaconda
pyasn1-modules            0.2.7                      py_0    anaconda
pycparser                 2.19                     py37_0    anaconda
pydicom                   1.4.1                      py_0    conda-forge
pydot                     1.4.1                    py37_0    anaconda
pydotplus                 2.0.2                    py37_1    anaconda
pygments                  2.5.2                      py_0    anaconda
pyjwt                     1.7.1                    py37_0    anaconda
pyopenssl                 19.1.0                   py37_0    anaconda
pyparsing                 2.4.6                      py_0    anaconda
pyqt                      5.9.2            py37h22d08a2_1    anaconda
pyrsistent                0.15.7           py37h7b6447c_0    anaconda
pysocks                   1.7.1                    py37_0    anaconda
pytables                  3.6.1            py37h71ec239_0    anaconda
python                    3.7.6                h0371630_2    anaconda
python-dateutil           2.8.1                      py_0    anaconda
pytz                      2019.3                     py_0    anaconda
pyzmq                     18.1.1           py37he6710b0_0    anaconda
qt                        5.9.7                h5867ecd_1    anaconda
rdflib                    4.2.2                 py37_1000    conda-forge
readline                  7.0                  h7b6447c_5    anaconda
requests                  2.22.0                   py37_1    anaconda
requests-oauthlib         1.3.0                      py_0    anaconda
rsa                       4.0                        py_0    anaconda
scipy                     1.4.1            py37h0b6359f_0    anaconda
send2trash                1.5.0                    py37_0    anaconda
setuptools                45.2.0                   py37_0    anaconda
simpleitk                 1.2.4            py37hf484d3e_0    simpleitk
simplejson                3.17.0           py37h7b6447c_0    anaconda
sip                       4.19.13          py37he6710b0_0    anaconda
six                       1.14.0                   py37_0    anaconda
sparqlwrapper             1.8.2                 py37_1000    conda-forge
sqlite                    3.31.1               h7b6447c_0    anaconda
tensorboard               2.1.0                     py3_0    anaconda
tensorflow                2.1.0           mkl_py37h80a91df_0    anaconda
tensorflow-base           2.1.0           mkl_py37h6d63fb7_0    anaconda
tensorflow-estimator      2.1.0              pyhd54b08b_0    anaconda
termcolor                 1.1.0                    py37_1    anaconda
terminado                 0.8.3                    py37_0    anaconda
testpath                  0.4.4                      py_0    anaconda
tk                        8.6.8                hbc83047_0    anaconda
tornado                   6.0.3            py37h7b6447c_3    anaconda
traitlets                 4.3.3                    py37_0    anaconda
traits                    5.2.0            py37h7b6447c_0    anaconda
urllib3                   1.25.8                   py37_0    anaconda
wcwidth                   0.1.8                      py_0    anaconda
webencodings              0.5.1                    py37_1    anaconda
werkzeug                  1.0.0                      py_0    anaconda
wheel                     0.34.2                   py37_0    anaconda
wrapt                     1.11.2           py37h7b6447c_0    anaconda
xvfbwrapper               0.2.9                 py37_1001    conda-forge
xz                        5.2.4                h14c3975_4    anaconda
zeromq                    4.3.1                he6710b0_3    anaconda
zipp                      2.2.0                      py_0    anaconda
zlib                      1.2.11               h7b6447c_3    anaconda
zstd                      1.3.7                h0b5b093_0    anaconda
Iguananaut
  • 21,810
  • 5
  • 50
  • 63
0

Thank you for your help !

It is an env problem from jupyter indeed. TF + pydicom created a bug beacause of the downgrade to python3.7 : jupyter notebook was not findind pydicom.

It seems to exist 2 solutions :

  • install jupyter in your custom env

    conda install -c conda-forge jupyterlab

  • update the index of anaconda.

Open Anaconda Navigator find "Environments" tab in the top left corner, click on it. You will see a long list of packages. Click the "Update index..." button at the top of the list.

Alex Nérot
  • 1
  • 1
  • 2