Kiyokawa / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Install PyDicom (I am using FreeBSD 8.0, package is called py26-pydicom)
2. Open python interpreter, type import dicom, then dir(dicom) - it works
3. 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 reported on code.google.com by tomek.ce...@gmail.com on 28 May 2010 at 9:15

GoogleCodeExporter commented 8 years ago
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

Original comment by darcymason@gmail.com on 28 May 2010 at 11:46

GoogleCodeExporter commented 8 years ago
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']

2. 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 <module>
    import dicom
  File "/mnt/stuff/cederom/moje/eclipse/dicomtagslayer/dicomtagslayer/src/dicom.py", 
line 5, in <module>
    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/testcharset
files
/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

Original comment by tomek.ce...@gmail.com on 29 May 2010 at 9:00

GoogleCodeExporter commented 8 years ago
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! :-)

Original comment by tomek.ce...@gmail.com on 29 May 2010 at 10:20

GoogleCodeExporter commented 8 years ago
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.

Original comment by darcymason@gmail.com on 29 May 2010 at 2:25