1

so I'm on a Windows 8 and I'm doing some image analysis for my research. It requires running this python script (I did not write it) called "calculate_distances.py". I am also using CellTool (http://pantheon.yale.edu/~zp2/Celltool/) and Numpy which I have successfully installed.

When I try to run my calculate_distances script, I get this error:

Traceback (most recent call last):
file "calculate_distances.py" line 4, in <module>
import celltool.simple_interface as si
ImportError: No module named celltool.simple_interface

Here is my calculate_distances.py script:

#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# Import various celltool modules

import celltool.simple_interface as si
import celltool.contour.contour_class as contour_class
from celltool.utility.path import path
import celltool.utility.datafile as datafile
import numpy

# Designate your working directory - ie, replace '/parent_directory/' with the path that contains your contour files
#parent_dir=path('/parent_directory/')
parent_dir=path('./')

# Identify and load  all of the contour files
contour_files=parent_dir.files('*.contour')
contours=si.load_contours(contour_files)
all_distances=numpy.arange(len(contours[0].points))

# Calculate the normal displacement of the cell boundary at every contour point.
n=1
while n<len(contours):
contour_class.Contour.global_reorder_points(contours[n],contours[n-1])
displacement_vectors = contours[n-1].points - contours[n].points
normals = contours[n-1].inward_normals()
distances  = (normals * displacement_vectors).sum(axis=1)
all_distances=numpy.vstack((all_distances,distances))
n=n+1

# Save a csv file with the normal displacement of the boundary at each contour point (columns) at each time point (rows)
datafile.write_data_file(all_distances,parent_dir/'distances.csv')

I have no idea what the error means, as I'm a first-time programmer. First I thought I needed to install a C++/fortran compiler, so I installed Simple Fortran, but it still does not work. Everything works fine on Mac system (after I installed GNU fortran) but for some reason it's not working on Windows. Is it because my CellTool is not installed in the right location? Or is it something with the script?

Any ideas? Thanks very much for your help!!

jamylak
  • 128,818
  • 30
  • 231
  • 230
yxnsn
  • 13
  • 2
  • Is `simple_interface` a function or class from `celltool`, or is it a submodule? This will make a difference in the answer you will need. The error is telling you that it can't find something you are trying to import. – SethMMorton May 22 '13 at 17:45
  • @SethMMorton Sorry, I don't know much programming vocab so I'm not sure what simple_interface refers to. [CellTool](http://pantheon.yale.edu/~zp2/Celltool/) is the only resource I have and it doesn't say anything specific on there. Any suggestions on what I could do? Thanks! – yxnsn May 22 '13 at 18:01
  • It looks like celltool is a command line program. It doesn't mention anything about a python API (application programming interface). Are you sure that you can use it within a python script? – SethMMorton May 22 '13 at 18:07
  • Yes, CellTool is in command line/terminal. I was previously using a OSX 10.8/Python 2.7.2 and everything worked perfectly, I applied the same steps to Windows 8, and I get the error. Could it be that it's incompatible with Windows? – yxnsn May 22 '13 at 18:14
  • I downloaded the celltool source, and I do see that they provide an [API](https://en.wikipedia.org/wiki/Application_programming_interface). The documentation you linked to doesn't mention it, so what did you use as a template for the script you posted? Also, if you have a script that only says `import celltool` do you get an error? – SethMMorton May 22 '13 at 18:16
  • You should have mentioned that the script worked on OSX, it would have made this easier to debug. It sounds like you might not have installed it correctly. Did the `import celltool` thing give an error? – SethMMorton May 22 '13 at 18:18
  • Sorry, I stated that it worked on Mac in the description. And yes, I get an error with `import celltool`. But no error with `celltool`. – yxnsn May 22 '13 at 18:27
  • I missed that, sorry. Since you get an error with just `import celltool`, that means that python cannot locate your installation. Where is it installed? I'm not sure what you mean when you say there's no error with `celltool`... do you mean the command line program itself? – SethMMorton May 22 '13 at 18:32
  • I installed it to my C drive in the Program Files. So yeah, when I type `import celltool` I get an error, but when I type `celltool` to activate the program, it does so without problems. I'm pretty sure you're right in that python can't locate it. I tried putting the source files for CellTool and Python in the same Program Files, but still no luck. I think it's a very simple issue, I just don't know how to resolve it! And thanks so much for your help. – yxnsn May 22 '13 at 18:53
  • Add the path CellTool to the `PYTHONPATH` using the instructions posted in this answer: http://stackoverflow.com/a/4855685/1399279. Then try again. You may need to open a new command prompt afterwords. – SethMMorton May 22 '13 at 20:37

1 Answers1

0

You have two options then.

  1. Try adding CellTool installation directory to your PYTHONPATH environment variable, if you haven't already (create this variable if necessary). Search for something like celltool.dll or libcelltool.dll (or even celltool.py). See if it helps. If not :
  2. Compile the source by following those few steps... Install MinGW (installer here), checking C/C++ (gcc/g++) and Fortran when asked by the installer. Then add C:/MinGW/bin (or whereever you installed MinGW) to your PATH environment variable. Download and unpack CellTool source package from the web site. Finally open a command shell (search for cmd program), change directory to the newly unpacked directory and build by typing :

    python setup.py install

This should properly compile and install the celltool python package to the site-packages directory of your Python installation. Option 2 is the sure/safe (but not easiest, I agree) way to get it work.

Gauthier Boaglio
  • 10,054
  • 5
  • 48
  • 85