suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

"import dicom" in PyDev/Eclipse does not work, but works fine in interpreter #86

Closed suever closed 9 years ago

suever commented 9 years ago

From tomek.ce...@gmail.com on May 28, 2010 17:15:40

What steps will reproduce the problem? 1. Install PyDicom (I am using FreeBSD 8.0, package is called py26-pydicom)

  1. Open python interpreter, type import dicom, then dir(dicom) - it works
  2. Open Eclipse and PyDev project, type import dicom - it does not work What is the expected output? What do you see instead? PyDicom should work in Eclipse - maybe some strange package format is being used? What version of the product are you using? pydicom-0.9.2 _NOTE_: any text or attached files posted with the issue can be viewed by anyone. You are solely responsible to ensure that they contain no confidential information of any kind. Please provide any additional information below.

Original issue: http://code.google.com/p/pydicom/issues/detail?id=86

suever commented 9 years ago

From darcymason@gmail.com on May 28, 2010 16:46:15

By 'it does not work' on the import, do you get the error, 'No module named dicom'? If it is some other error, please post it.

I'm not an Eclipse user, but if the error is "no module named dicom", then I suspect this is related to python's path, or with the version of python being used. Are the python versions's the same? (can check on interpreter startup or with sys.version).

If they are using different versions of python, then pydicom will need to be re-installed for the Eclipse version of python.

If the python versions are the same, then maybe comparing sys.path of the two would help. Check if pydicom (as folder 'dicom'') is in one of the locations in sys.path (it normally installs to python's usual site-packages directory).

Hope that helps Darcy

suever commented 9 years ago

From tomek.ce...@gmail.com on May 29, 2010 02:00:27

Hello Darcy!

Thank you for prompt response! The python interpreter is the same in presented description:

  1. Python shell:

    import sys sys.version '2.6.2 ( r262 :71600, Sep 18 2009, 10:06:20) \n[GCC 4.2.1 20070719 [FreeBSD]]'

  2. Eclipse pydev: import sys print(sys.version)

2.6.2 ( r262 :71600, Sep 18 2009, 10:06:20) [GCC 4.2.1 20070719 [FreeBSD]]

It looks that the shell interpreter can see and access the dicom module components, while PyDev does not:

1.Python shell:

import dicom dir(dicom) ['ReadFile', 'UID', 'WriteFile', '_UID_dict', 'builtins', 'doc', 'file', 'name', 'package', 'path', '_dicom_dict', 'charset', 'datadict', 'dataelem', 'dataset', 'debug', 'filebase', 'filereader', 'filewriter', 'formatter', 'handler', 'logger', 'logging', 'sequence', 'tag', 'valuerep']

  1. For this code in Eclipse PyDev I get nothing. When I try to rad file with code: import dicom file=dicom.filereader.ReadFile("../data/test.dcm")

I get following traceback:

Traceback (most recent call last): File "/mnt/stuff/cederom/moje/eclipse/dicomtagslayer/dicomtagslayer/src/dicom.py", line 4, in import dicom File "/mnt/stuff/cederom/moje/eclipse/dicomtagslayer/dicomtagslayer/src/dicom.py", line 5, in file=dicom.filereader.ReadFile("../data/test.dcm") AttributeError: 'module' object has no attribute 'filereader'

Here goes the directory structure of the installed package:

%find /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/ -type d /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/ /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/EGG-INFO /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/doc /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/examples /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/test /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/testcharsetfiles /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/testfiles /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom/util

When I set the PYTHONPATH to /usr/local/lib/python2.6/site-packages/pydicom-0.9.2- py2.6.egg/ and /usr/local/lib/python2.6/site-packages/pydicom-0.9.2-py2.6.egg/dicom nothing changes.

Maybe someone had this problem before and know working solution? :-)

Best regards, Tomek Cedro

suever commented 9 years ago

From tomek.ce...@gmail.com on May 29, 2010 03:20:52

Hahahaha!!! I am new to Python, so I made a silly mistake - in my project I have named "dicom.py" a module responsible for dicom operations, while this file was trying to include system wide "dicom" module - local path won, so it was impossible to import PyDicom. I have renamed my file into "dcm.py" and everything works fine! Thank you and sorry for false alert! :-)

suever commented 9 years ago

From darcymason@gmail.com on May 29, 2010 07:25:12

Ah. The way python's import works makes it easy for these kinds of things to happen, unfortunately. Glad you were able to find the solution.

Status: Done