Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-19-2015, 04:47 PM
7ticks 7ticks is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
openpyxl module import error

Hello, could you help me understand the reason why I receive "Error: No module named openpyxl" error when I run my script? I want to use 3rd party Python module called "openpyxl" in my script. Most likely you are familiar with this module, which allows Python to interact with Excel files. My goal is to read list of commands, which are contained inside Excel file, and then run these commands on multiple hosts within SecureCRT. Essentially, I am using modified version of "MultiSessionSend.py" script, which is listed on Python scripts support page. I already have "openpyxl" module installed on my PC (Windows 7), and it works fine within Python scripts that I run directly (outside of SecureCRT). Does it imply that when I run Python script via SecureCRT, Python for some reason does not use standard search path to look for appropriate module?

Thank you in advance
Reply With Quote
  #2  
Old 06-19-2015, 06:12 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi 7ticks,

Thanks for the post.

What version of SecureCRT are you using?

What version of Python is the module expected to work with?

What version of Python is installed on your machine?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 06-19-2015, 08:45 PM
7ticks 7ticks is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
openpyxl module import error

Hello Todd,

I am running version 7.3.2 of SecureCRT. Python installed version is 3.4.2. "openpyxl" module version is 2.2.2. As I posted initially, I have no problem running this module outside of launching Python scripts from SecureCRT. I only get import error when I attempt to run script from SecureCRT.
Reply With Quote
  #4  
Old 06-20-2015, 07:51 PM
7ticks 7ticks is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
openpyxl module import error

Hello Tod, I have version 7.3.2 of SecureCRT installed. I run Python version 3.4.2. Module "openpyxl" version is 2.2.2 installed in this directory c:\python34\lib\site-packages\openpyxl.
Reply With Quote
  #5  
Old 06-22-2015, 09:44 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi 7ticks,

SecureCRT isn't expected to work with Python 3.4. Further, it isn't expected to work with anything external to the Python included in the installation folder.

You may consider injecting the module path into sys.path. For example:
import sys
import os
# sys.path is a variable that tells a script where to look for modules when
# importing them. Here is an example of how to add a path you want to use if
# you don't want to use a pre-defined path. This also illustrates how to
# determine the valid paths defined in sys.path.

# Display current sys.path list.
crt.Dialog.MessageBox(str(sys.path))
# Get the path to the script that is running that wants to import a module
(strScriptPath, strScriptName) = os.path.split(__file__)
# Inject the path to the script into sys.path for use when looking for modules
# to import.
if strScriptPath in sys.path:
# If the path exists, don't inject. Unless SecureCRT is closed, we don't
# need to inject the path of the running script because sys.path is static.
crt.Dialog.MessageBox("Already There")
else:
# Inject the path of the running script if it is not in sys.path
sys.path.insert(0, strScriptPath)
# Confirm that your custom path has been injected into the sys.path list.
crt.Dialog.MessageBox(str(sys.path))
# Import custom module.
.
.
.
If that doesn't work, you may consider installing Python 2.6 since SecureCRT 7.3 uses 2.6.

I am interested to know if you are able to find a solution, so please post your testing results.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #6  
Old 06-23-2015, 05:42 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi 7ticks,

I have not found a way to make the SecureCRT 7.3 Python environment successfully import modules like openpyxl.

You have one potential option at this point. You can use an external Python 2.6 environment, and I do mean Python 2.6 when using SecureCRT 7.3.x.

Once you have Python 2.6 installed, close SecureCRT and rename python.dll and python.zip which are located in the SecureCRT installation folder. Now when you launch SecureCRT, you should be able to import openpyxl.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 06-26-2015, 11:51 AM
7ticks 7ticks is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
openpyxl module import error

Hello Todd, I will try going through your recommendation of installing Python 2.6 later on. Right now, I made a work around, where I generate text files from the input Excel file. This allows me to use standard library modules in built in version of Python 2.6, which comes with SecureCRT. It is an extra step, but not a difficult one since it only involves double clicking another Python script.

I think that built-in Python version, which comes with SecureCRT could potentially import openpyxl module. After I copied "openpyxl" folder to one of the folders in the sys.path used by built-in Python version, I received another error, in which Python was complaining about import of yet another 3rd party module called "jdcal". This tells me that Python tried to import "openpyxl" module, but because openpyxl in turn imports other 3rd party modules - the actual import still failed. If all import dependencies have been resolved then import probably worked.

I am kind of curious why there is such tight requirement between SecureCRT and specific Python version, in this case 2.6? I would think that Python interpreter just needs to be able to communicate with SecureCRT via API calls. Is it possible to create a Python module, which would relax this requirement?
Reply With Quote
  #8  
Old 06-26-2015, 12:52 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi 7ticks,
Quote:
Hello Todd, I will try going through your recommendation of installing Python 2.6 later on. Right now, I made a work around, where I generate text files from the input Excel file. This allows me to use standard library modules in built in version of Python 2.6, which comes with SecureCRT. It is an extra step, but not a difficult one since it only involves double clicking another Python script.
I am glad to hear that you found a solution.


Quote:
I think that built-in Python version, which comes with SecureCRT could potentially import openpyxl module. After I copied "openpyxl" folder to one of the folders in the sys.path used by built-in Python version, I received another error, in which Python was complaining about import of yet another 3rd party module called "jdcal". This tells me that Python tried to import "openpyxl" module, but because openpyxl in turn imports other 3rd party modules - the actual import still failed. If all import dependencies have been resolved then import probably worked.
I have spent hours and hours testing these same possibilities only to not find a solution. If you find one, please post it.


Quote:
I am kind of curious why there is such tight requirement between SecureCRT and specific Python version, in this case 2.6? I would think that Python interpreter just needs to be able to communicate with SecureCRT via API calls. Is it possible to create a Python module, which would relax this requirement?
I can't speak to the reasons why. It sounds like you want SecureCRT to expose the scripting API to external programs.

Is this correct?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:38 PM.