Error executing pydicom

540 views
Skip to first unread message

MasatoDicom

unread,
Dec 15, 2010, 3:19:01 AM12/15/10
to pydicom
Hello,

I recently installed "pydicom" and got the following error while
trying to read a dicom file. The dicom file is present inside the
"testfiles" folder that is installed under site-packages/dicom/ folder
while installing "pydicom".

I am using Python 2.7.1 under Microsoft Windows XP.

I got the following errors:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import dicom
>>> ds=dicom.read_file("CT_small.dcm")


Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
ds=dicom.read_file("CT_small.dcm")
File "C:\Python27\lib\site-packages\dicom\filereader.py", line 460,
in read_file
fp = open(fp, 'rb')
IOError: [Errno 2] No such file or directory: 'CT_small.dcm'
>>> import dicom
>>> ds = dicom.read_file("rtplan.dcm")

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
ds = dicom.read_file("rtplan.dcm")
File "C:\Python27\lib\site-packages\dicom\filereader.py", line 460,
in read_file
fp = open(fp, 'rb')
IOError: [Errno 2] No such file or directory: 'rtplan.dcm'
>>>

How can I solve the above problem?

Thank you.
With best regards.

Darcy Mason

unread,
Dec 15, 2010, 8:33:04 AM12/15/10
to pydicom
On Dec 15, 3:19 am, MasatoDicom <amirkom...@gmail.com> wrote:
> I recently installed "pydicom" and got the following error while
> trying to read a dicom file. The dicom file is present inside the
> "testfiles" folder that is installed under site-packages/dicom/ folder
> while installing "pydicom".
>
> ...
> >>> import dicom
> >>> ds=dicom.read_file("CT_small.dcm")
>
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in <module>
>     ds=dicom.read_file("CT_small.dcm")
>   File "C:\Python27\lib\site-packages\dicom\filereader.py", line 460,
> in read_file
>     fp = open(fp, 'rb')
> IOError: [Errno 2] No such file or directory: 'CT_small.dcm'
>

It's probably just a case of needing to change the working directory:
>>> import os
>>> os.getcwd() # to see where you are
>>> os.chdir('<path-to-testfiles>') # to change directory

or, can open the file with a full path; in your case it should be
>>> dicom.read_file(r"c:\Python27\lib\site-packages\dicom\testfiles\CT_small.dcm")

The examples from the pydicom website assume the working directory is
the testfiles directory.

-Darcy
Reply all
Reply to author
Forward
0 new messages