title: No Module Named Socket
body: <p>Im trying to use the socket module in a logon script for SecureCRT. When run from my command line, the script runs perfectly but once I try to run it through SecureCRT it tells me there is no socket module.
  Im using python 3.7 and have made sure socket is in my lib. My lib is also mapped for path.</p>
  
  <p>Here is the script Im running:</p>
  
  <pre><code>import socket
  import datetime
  timeIn=(datetime.datetime.now().strftime('%d %B %Y %H:%M:%S'))
  hostname = socket.gethostname()
  hostip = socket.gethostbyname(hostname)
  t=open("secCRT.txt", "w")
  t.write('testing script \n')
  t.write(timeIn)
  t.write(' host: '+  hostname)
  t.write(' ip: '+ hostip)
  t.close()
  </code></pre>
  
  <p>When run from my command line it works perfectly but when run inside crt, it states there is no module named socket (no module named _socket).
  Ive seen there are similar posts to this but none that have been able to help me yet.</p>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>Here is the way python is mapped to the path system variable:</p>
  
  <p><a href="https://i.stack.imgur.com/TWcl8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TWcl8.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT #2</strong></p>
  
  <p>Tried moving _socket.py and socket.py for version 3.7 to the same directory as the script but still getting errors. <strong>edit*</strong> also socket.cpython-37.pyc</p>
  
  <p><strong>EDIT #3</strong></p>
  
  <p>Im wondering, because this is a logon script (run when a connection is made to a server), could it be looking for the socket module on the server im connected to instead of the local machine? The script itself is on the local machine.</p>
  
  <p><strong>EDIT #4</strong> : from command line not logon script</p>
  
  <pre><code>&gt;&gt;&gt; import sys
  &gt;&gt;&gt; import pprint
  &gt;&gt;&gt; pprint.pprint(sys.path)
  ['',
   'C:\\Program Files\\Python\\Python37\\python37.zip',
   'C:\\Program Files\\Python\\Python37\\DLLs',
   'C:\\Program Files\\Python\\Python37\\lib',
   'C:\\Program Files\\Python\\Python37',
   'C:\\Program Files\\Python\\Python37\\lib\\site-packages']
  </code></pre>
  
  <p><strong>EDIT #5</strong></p>
  
  <p>I was able to do this as a script within the SecureCRT application</p>
  
  <pre><code>with open("secCRT.txt", "w") as sout:
      sout.write(pprint.pformat(vars(pprint)))
  </code></pre>
  
  <p>Several of the lines reference this file: </p>
  
  <pre><code>C:\Program Files\VanDyke Software\Clients\vpython27.zip
  </code></pre>
  
  <p>This leads me to believe they are using verison 2.7. When I searched inside <code>vpython27.zip</code> for "socket" the <code>socket.pyc</code> and <code>SocketServer.pyc</code> were the only items that came up.
  Does this mean I would want to find a <code>socket.py</code> or any other dependencies for version 2.7 and move them there?</p>
  
  <p><strong>EDIT #6</strong> : explanation from developer (VanDyke)</p>
  
  <pre><code>"  - The _socket module is built out by default as a .pyd
      file on Windows. This is effectively a .dll that can be
      loaded by the Python interpreter. Unfortunately, .pyd's
      can *not* be loaded out of the Python distribution zip
      file we ship."
  </code></pre>
  
  <p><strong>EDIT #7</strong> : here is how VanDyke suggested I get the data I was looking for </p>
  
  <pre><code>objTab=crt.GetScriptTab()
  objConfig=objTab.Session.Config
  strHostname=objConfig.GetOption('Hostname')
  strSessName=objTab.Session.Path
  </code></pre>
  
  <p>This solution works great for my environment.</p>