Project

General

Profile

updatecom.py problem in Leginon 1.6

Added by Anonymous about 15 years ago

I tried to install the film exposure adaptor on the Windows machine controlling the microscope according to the instructions on pg. 41 of the Leginon-1.6-ALL manual. I followed the instructions sent to me by Dr. Otten and reiterated in the Leginon manual, but when I ran the updatecom.py script, I got an error:

C:\Python25\Lib\site-packages\pyScope>updatecom.py
Generating .py files from type libraries...
Tecnai Scripting:
Traceback (most recent call last):

File "C:\Python25\Lib\site-packages\pyScope\updatecom.py", line 47, in <module>

run()

File "C:\Python25\Lib\site-packages\pyScope\updatecom.py", line 43, in run

makeFile(desc, filename)

File "C:\Python25\Lib\site-packages\pyScope\updatecom.py", line 34, in makeFile

progressInstance=makepy.SimpleProgress(0))

File "C:\Python25\lib\site-packages\win32com\client\makepy.py", line 279, in GenerateFromTypeLibSpec

gen.generate(fileUse, bForDemand)

File "C:\Python25\Lib\site-packages\win32com\client\genpy.py", line 796, in generate

self.do_generate()

File "C:\Python25\Lib\site-packages\win32com\client\genpy.py", line 857, in do_generate

self.do_gen_file_header()

File "C:\Python25\Lib\site-packages\win32com\client\genpy.py", line 814, in do_gen_file_header

assert self.file.encoding, self.file
AssertionError: <open file 'tecnaicom.py', mode 'w' at 0x00BEDDE8>

Adaexp.exe is in the right folder (C:\tecnai\tools) and I ran the "adaexp.exe /regserver" command from inside that folder before running the python script. Just wanted to check here to see if it was a common, easily fixable problem or whether I should contact Dr. Otten again to see if I should get another copy.

Thanks for the help!


Replies (14)

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

This may not be particular to adaExp. It looks more like a permissions problem writing to a file. Maybe you need to be administrator? The file that it is trying to create is in:
C:\Python25\Lib\site-packages\pyScope\
updatecom.py generates a few new python files in that folder.
Try going into the folder and creating a new test file to see if you have permission to write to that folder. Maybe the file tecnaicom.py already exists from a previous run of updatecom.py and now you cannot overwrite it. Try removing it and any other ...com.py files that were generated by updatecom.py. (just don't remove the updatecom.py script)

Let me know if you do not discover the problem and I will think of another option.

Re: adaexp installation - Added by Anonymous about 15 years ago

Thanks for the help; I tried checking what you suggested. I am logged on as the administrator, and I seem to have permissions to write, read, and execute. I tried removing the tecnaicom.py file from the pyScope folder (it was the only ...com.py file besides updatecom.py), but executing updatecom.py didn't seem to fix the problem--it created an identical tecnaicom.py file that was blank.

I tried checking the gen.py file the script is calling up. It says that it's getting stuck on:

"assert self.file.encoding, self.file"

There is a comment above it saying that:

  1. You must provide a file correctly configured for writing unicode.
  2. We assert this is it [sic] may indicate somewhere in pywin32 that needs
  3. upgrading.

Do I need to have some form of extension that allows me to write python code in Unicode? When I had the choice of installing wxPython2.8, I chose to install wxPython2.8-win32-ansi-2.8.10.1-py25.exe instead of wxPython2.8-win32-unicode-2.8.10.1-py25.exe. That was the only time in the installation in which I had to choose.

Think reinstalling just that package might work?

Re: adaexp installation - Added by Anonymous about 15 years ago

Just tried reinstalling wxPython, but I am still getting the same error. At least now my Python scripts be can writen in Unicode! <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" />

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

Did you find a solution to this updatecom.py error? Or does this not affect Leginon working?

Re: adaexp installation - Added by Anonymous about 15 years ago

Unfortunately, it's still not working.

In addition to setting up the Linux machine on the Tecnai T20, I also tried connecting the Linux server/database to a Windows machine controlling a Tecnai T12. Though I did not try running the film adapter program in this one, I got the same assert error and the script stops when trying to write the com.py files, so I think I might be able to rule out the adaexp.exe (which I suppose is optional if we only use the CCD), unless the problem *is being caused by the adaexp.exe not being installed properly.

Also, I realized when setting up the second computer that the TEMs share the same name (tecnai.Tecnai) even though they are different models and are only differentiated in Leginon by the hostname of the windows machine. Is there any way of keeping that less ambiguous? Has that been a problem for other people with similar setups? I'm just afraid that the Linux machine (or the user!) might inadvertently use the T20 settings on the T12 (or vice versa). The importing of the instruments seemed to me to be a little vague.

Not sure if all of this is related to the updatecom.py problem, but I think it falls under the scope of PyScope.

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

Yes, I think adaexp should be optional for most cases. You can try to remove the adaExp line from updatecom.py and see if that gets around the problem. If there are other problems with updatecom.py, then I have another solution that may work, but let me know.

It is true that the host name of the Windows computer is the unique field in the database. The names of the fields that you fill in the import instruments are confusing. "Name" is not unique and can be Tecnai for more than one system. Instead of "Name", this should probably be called "Class", because that is what it is called in the instruments.cfg file in pyScope. "Tecnai" is the class of driver that is used to communicate with the TEM, and all models (T12, TF30, etc.. ) all use the same "Tecnai" driver. This has never caused any problems for us. We have three different Tecnai TEMs, and people just know them by their host names: tecnai1, tecnai2, and spirit1.
pyScope actually does not care about the database, and only gets information from the instruments.cfg file to know which type of TEM you have. When you start up Leginon, you have to tell it which client to connect to. This is where you select the host name of the TEM you want to use. Then Leginon is talking to pyScope on that host, and knows which TEM and camera drivers to use.

Re: adaexp installation - Added by Anonymous about 15 years ago

Thank you for the information. Again, sorry to be such a downer, but updatecom.py is still not working properly. I tried reinstalling the pywin32 extension since the last script it falters on refers to it in the assert error, saying that I might need a more recent version of pywin32 for it to work (it's in the comments of the script). Unfortunately, it appears to be the latest version (build 214, python 2.5) that I can use, so I don't know if that's the problem. In summary: updatecom.py is giving me the exact same error.

The name--or rather, class--of the instruments is clearer to me now, but I'm confused about how it might deal with our particular set up. I just found out today that our TF20 microscope also happens to have not just one Gatan camera, but two. One is for film and one is a CCD camera. Since they are on the same microscope and computer, they are on the same host, so differentiating between them is confusing. Anyone else deal with the same problem? I've named the CCD camera with the header [cam1] in the instruments.cfg file, but I don't know how it's going to differentiate between them in the web tools.

So far, we've been able to actually connect to the microscope using the Linux machine and were able to collect some (real images); we're going to move on to calibration soon. I'm happy it's working, but there's some questions I still have concerning that (I'll post them elsewhere, since I don't think they are directly related to pyScope).

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

The updatecom.py problem will need some testing here to see if I can reproduce it. It will be pretty busy here with a workshop for the next two weeks so it may be a while before this gets resolved.

On the topic of multiple Gatan cameras:
pyScope communicates with a Gatan camera through tecnaiccd.dll, which in turn communicates with Digital Micrograph. I have never encountered multiple cameras, but I suspect it would work by only establishing one connection to the tecnaiccd.dll, then selecting which camera to use through some function call. The selection of which camera to use is not implemented in the pyScope/gatan.py module, but you should probably just configure pyScope/instruments.cfg as though you only have one camera, such as

[Camera]
class: gatan.Gatan
Then I assume you can select which camera to use in Digital Micrograph. I think Leginon will just use whatever current camera is selected. The tecnaiccd.dll appears to have some functions that relate to selecting the current camera, so we could add that in gatan.py. This may only be necessary if you want Leginon to switch between them. If you only intend to use Leginon with the CCD, then hopefully doing the selection in DigitalMicrograph will be successful. Let me know if that will work.

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

The updatecom.py script is very outdated and needs work. I have another solution that you can try. Eventually this can be done by updatecom.py, but for now here is the step by step procedure that may work, or it may give you the same error. I have not had time to try this on our Tecnai yet, so you are the first experiment. If this turns out to work, we can revise how updatecom.py works. Here is the procedure:

1) make a backup of C:\python25\lib\site-packages\pyScope (or just reinstall it from scratch if you mess it up too bad)

2) remove any of those *com.py files that updatecom.py generated (sounds like you only had an empty tecnaicom.py)

3) Look inside the updatecom.py script. There is a list something like this, depending on your version of pyScope:

info = [

('Tecnai Scripting', 'tecnaicom.py', 'Tecnai Scripting'),

('Low Dose Server Library', 'ldcom.py', 'Tecnai Low Dose Kit'),

('adaExp Library', 'adacom.py', 'Tecnai Exposure Adaptor'),

('TecnaiCCD 1.0 Type Library', 'gatancom.py', 'Gatan CCD Camera'),

('CAMC4 1.0 Type Library', 'tietzcom.py', 'Tietz CCD Camera'),
]

4) For each item in that list (for example "Tecnai Scripting", Low Dose Server Library", etc):
a) Run this script: C:\python25\lib\site-packages\win32com\client\makepy.py
b) Select the item from the pop up window (you can only select one thing at a time).
c) Click "ok"
d) If the makepy.py list does not contain the item, the just skip to the next one. (for instance, if you do not have a Tietz camera, you will not have "CAMC4..."
e) repeat makepy.py for all the other items...

5) Check for new generated python modules in: C:\python25\lib\site-packages\win32com\gen_py\. There should be a python module for each time you ran makepy.py. Although they have very strange long file names, these are the same files that updatecom.py was attempting to generate.

6) Now in pyScope, we need to edit any of the scripts that were trying to find the *com.py scripts, because we do not need them anymore. Python will automatically use the modules generated by makepy.py in the gen_py folder. In tecnai.py, gatan.py, etc, look for any lines regarding "import tecnaicom" or "import gatancom" etc.

Let me know what happens.

Jim

Re: adaexp installation - Added by Anonymous about 15 years ago

Hi Jim,

I tried what you suggested, but unfortunately, I ran into another problem (though I think it will help us narrow down what is the matter)--the excerpt from updatecom.py file showing the different scripts looks like this:

info = [

('Tecnai Scripting', 'tecnaicom.py', 'Tecnai Scripting'),

('Low Dose Server Library', 'ldcom.py', 'Tecnai Low Dose Kit'),

('adaExp Library', 'adacom.py', 'Tecnai Exposure Adaptor'),

('TecnaiCCD 1.0 Type Library', 'gatancom.py', 'Gatan CCD Camera'),

('CAMC4 1.0 Type Library', 'tietzcom.py', 'Tietz CCD Camera'),
]

which is the same as the one you showed me. Only two are missing: ('Tecnai Scripting', 'tecnaicom.py', 'Tecnai Scripting') and ('
CAMC4 1.0 Type Library', 'tietzcom.py', 'Tietz CCD Camera'). We don't have a tiezt camera, so that doesn't bother us as much, but we do have a Tecnai scope that appears to be missing some script files. I suspect that this might be the reason why it's not writing the tecnaicom.py script properly. There were some other Tecnai scripts present, but they were called:

TecnaiServer 1.0 Type Library (1.0)
Tecnai CCD 1.0 Type Library (1.0)
TecnaiCheck 1.0 Type Library (1.0)
TecnaiPortal 1.0 Type Library (1.0)
TEM Scripting (1.9)

[/list:u:mj4t1kda]
(I'm not sure about the last one, and the CCD one is for the camera).

This is the summary of the relevant files that are missing and present:

present:
Low Dose Server Library', 'ldcom.py', 'Tecnai Low Dose Kit
TecnaiCCD 1.0 Type Library', 'gatancom.py', 'Gatan CCD Camera
adaExp Library', 'adacom.py', 'Tecnai Exposure Adaptor
TecnaiServer 1.0 Type Library (1.0)
Tecnai CCD 1.0 Type Library (1.0)
TecnaiCheck 1.0 Type Library (1.0)
TecnaiPortal 1.0 Type Library (1.0)
TEM Scripting (1.9)

missing:
Tecnai Scripting', 'tecnaicom.py', 'Tecnai Scripting
CAMC4 1.0 Type Library', 'tietzcom.py', 'Tietz CCD Camera

[/list:u:mj4t1kda]

Should I try running the make.py script for the other Tecnai files, or do I need to look for another script?

Thank you for your help!

Re: adaexp installation - Added by Anonymous about 15 years ago

Also, I wanted to ask you to clarify something--when you said

"6) Now in pyScope, we need to edit any of the scripts that were trying to find the *com.py scripts, because we do not need them anymore. Python will automatically use the modules generated by makepy.py in the gen_py folder. In tecnai.py, gatan.py, etc, look for any lines regarding "import tecnaicom" or "import gatancom" etc."

should I also be removing references to other *com.py files I didn't create using make.py (e.g. pythoncom)? Thanks!

Re: adaexp installation - Added by Anonymous about 15 years ago

Hi Jim,

I think that might have fixed our problems after all: I just ran the following script to see if I could control the stage using Python:

from pyScope import tecnai
t = tecnai.Tecnai()
t.setStagePosition({'x': 0, 'y': 0, 'z': 0})

Whenever I tried it before, I wouldn't hear anything from the microscope stage (no whirring or clicking), but after I followed your suggestions, I heard the stage move, which is what we were trying to do anyway. I ended up running makepy for all the Tecnai files I could find, so I'm not sure whether there was some redundancy in doing so or not.

I have yet to try to the Leginon client proper, but hopefully, it will work! I'll let you know what happens and whether we can proceed with the calibration.

Thank you again for your help!

Re: adaexp installation - Added by Anonymous about 15 years ago

Just wanted to confirm that I can move the stage using the Leginon instrument node, so I think we should be able to move on to calibrations from here! <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" />

Thank you so much for you assistance! I very much doubt we would have been able to resolve the issue ourselves. Also, I think the adaexp has been installed properly, but is there a quick way I can test it (besides actually taking a film micrograph?). It's not too important right now (as much as fixing the stage, anyway), but I thought I should bring back discussion to it since that's the name of the thread. <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

Re: adaexp installation - Added by Jim Pulokas about 15 years ago

Great to hear you got it working. It looks like the actual solution is that "TEM Scripting" is the replacement for "Tecnai Scripting" in newer versions of Tecnai. I had the fix for that in the development branch, but I am now adding that into the 1.6 branch.

    (1-14/14)