ArcGIS 10.2 - Which file the import time module references to?

3896
9
01-14-2016 06:23 AM
VincentLaunstorfer
Occasional Contributor III

Hi,

I have a python script tool importing several modules such as:

import sys, string, os, arcpy, time

In particular, I am interested in the time module because I call the time.strftime function in the script...

The tool works fine on my machine but fails to execute on another machine, crashing when the function time.strftime is called!

Therefore, I would like to find out which file on my machine the import time module references to. Then, I could copy this file on the other machine to make my tool works!

Thanks

0 Kudos
9 Replies
DanPatterson_Retired
MVP Emeritus

time is a standard python module

>>> import time

has to be a line in the script at the top of the script, or import it  at the interactive prompt, type it in to import the module as shown above

VincentLaunstorfer
Occasional Contributor III

It is already a line at the beginning of the script:

# Import system modules
import sys, string, os, arcpy, time

But the time module probably references to a file which is not on the other machine, I imagine. It works on mine...

0 Kudos
DanPatterson_Retired
MVP Emeritus

Then their python is either non-existent or installed improperly.  Try and locate the python path using windows explorer.  it will either be in

c:\Python27\.... or

c :\Python34\...

depending on the version of python.  If it is not a normal install, or a virtual install...have a chat with the other person to find out how it was installed. and check for a python path or python environment setting

VincentLaunstorfer
Occasional Contributor III

The Python looks installed correctly on the other machine with a C:\Python27\ArcGIS10.2\ folder containing the libraries and all the stuff... It looks like. This is why I was suspecting the file to which the time module references might be not in the right place!

Or there is a variable to set in order to indicate explicitly where to ook for Python libraries, modules...

In addition to find out the file the time module references to, where is it possible to check/set the path and other variable for Python?

Thanks

0 Kudos
DanPatterson_Retired
MVP Emeritus

What IDE are you using? PyScripter? PythonWin? just IDLE in ArcMap?

Dare I get you to try to import sys, but here is an example from PythonWin (pyscripter is the same) and python 3.4 the relevant ones have been highlighted.

>>> import sys
>>> sys.path
['', '...',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34\\Lib\\site-packages\\pythonwin',
 'C:\\Python34',
 'C:\\Python34\\lib\\site-packages',
 'C:\\Program Files\\ArcGIS\\Pro\\bin',
 'C:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcPy',
 'C:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcToolBox\\Scripts',
 'C:\\Python34\\lib\\site-packages\\win32',
 'C:\\Python34\\lib\\site-packages\\win32\\lib','...']
>>>

and from python 2.7

PythonWin 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> import sys
>>> sys.path
['', '...',
 'C:\\Python27\\ArcGIS10.3\\DLLs',
 'C:\\Python27\\ArcGIS10.3\\lib',
 'C:\\Python27\\ArcGIS10.3\\lib\\plat-win',
 'C:\\Python27\\ArcGIS10.3\\lib\\lib-tk',
 'C:\\Python27\\ArcGIS10.3\\Lib\\site-packages\\pythonwin',
 'C:\\Python27\\ArcGIS10.3',
 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\bin',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\ArcPy',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\ArcToolBox\\Scripts',
 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages\\win32',
 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages\\win32\\lib']
>>>

And of course yours may differ...I am using ArcGIS10.3.1 and ArcGIS PRO

DanPatterson_Retired
MVP Emeritus

I have posted a note on the topic of where to find modules here.

What is standard and not ... in python

DanPatterson_Retired
MVP Emeritus

problem solved? or still ongoing?

0 Kudos
VincentLaunstorfer
Occasional Contributor III

Thank you for asking about the time.strptime function in my script... And I appreciated the blog post.

Unfortunately, I cannot find out which file (or anything else) is missing on the other machines on which I wish to run the script.

The PythonWin gives me the following paths, but it doesn't tell me from which file the time.strptime is coming from!

For the time being, I intend to "suspend" any call to time.strptime even if it makes the script less efficient.

PythonWin 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python27.zip', 'C:\\Python27\\ArcGIS10.2\\DLLs', 'C:\\Python27\\ArcGIS10.2\\lib', 'C:\\Python27\\ArcGIS10.2\\lib\\plat-win',
'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk',
'C:\\Python27\\ArcGIS10.2\\Lib\\site-packages\\pythonwin',
'C:\\Python27\\ArcGIS10.2',
'C:\\Python27\\ArcGIS10.2\\lib\\site-packages',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\bin',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\arcpy',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\ArcToolbox\\Scripts',
'C:\\Python27\\ArcGIS10.2\\lib\\site-packages\\win32',
'C:\\Python27\\ArcGIS10.2\\lib\\site-packages\\win32\\lib']
>>>

I need to build up more knowledge about Python and arcpy to solve this sort of problems...

0 Kudos
DanPatterson_Retired
MVP Emeritus

again... time is built-in... there is no file like other files... python is being looked for in the wrong place or it is installed incorrectly or corrupt.   re-install it