santhosh
santhosh

Reputation: 21

ImportError: No module named _socket

I am trying to execute a small python code from CPP environment(Visual studio 2008) for test automation. When I try to add the following code in python script import socket. The python code is not getting imported. I am getting the below error.

Py_initialize succeededTraceback (most recent call last):
  File "E:\Code\MSVC\PythonTest\Proj\Pythoncheck\Debug\main.py", line 2, in <module>
    import socket
  File "C:\Python27\Lib\socket.py", line 47, in <module>
    import _socket
ImportError: No module named _socket

But when i execute the python script alone(python main.py), there is no such issue in importing socket. The python script is getting executed fine. Has anyone faced this earlier? Could anyone help me with the solution?

The code main.py contains

import sys
import socket

print"santhosh"

def startmain():

    while True:
        time.sleep(5000)


pingcount = 0
print "InstartMain"

Regards, Santhosh

Upvotes: 2

Views: 10093

Answers (1)

cudima
cudima

Reputation: 434

The environment where you are launching python might not be the same as the environment where you are launching your CPP program. Try setting PYTHONHOME

[I know this won't help the original poster, but I ran into this issue trying to use pythonnet from C# in 2018]

Upvotes: 2

Related Questions