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
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]
Related
I followed the instructions and successfully installed pypostal python package (package to help parse addresses) https://github.com/openvenues/pypostal.
I'm trying to set this up so the python script can be callable through an apache server on an ubuntu box. It works fine when executing the script from Terminal. However, it doesn't work when I make a call to apache to execute the script and I get the following error in the apache logs. I believe it might be some pathing issue but I haven't had much luck to resolve it. Any ideas will be appreciated.
Error:
File "/var/www/html/cgi-bin/get_parsedAddress.py", line 5, in
from postal.parser import parse_address
ModuleNotFoundError: No module named 'postal'
python script contents:
import sys
from postal.parser import parse_address
addressList = parse_address(sys.argv[1])
print(addressList)
Working on code that SSH's into terminal on an external device. This morning the code was able to do so. Then I updated Windows because I had put it off for a while. This was the only thing I did that I could think of may have had an effect.
I now run into a ModuleNotFoundError.
I tried updating pip, uninstalling and reinstalling ssh2-python. I changed python37 folder to read/write. Tried locating the module in python37/Lib/site-packages but not really sure what I'm looking for
SSH's into address' terminal
import socket
from ssh2.session import Session
Expected:
input for ip address
Result:
Traceback (most recent call last):
File "C:/Users/louis/Desktop/ssh2.py", line 4, in <module>
from ssh2.session import Session
File "C:\Users\louis\Desktop\ssh2.py", line 4, in <module>
from ssh2.session import Session
ModuleNotFoundError: No module named 'ssh2.session'; 'ssh2' is not a package
I had named a file in the same directory ssh2. Python loaded that instead of the module. Simply renamed the file to anything else and python was able to find the ssh2 module.
I'm trying to execute a python script on boot. The script runs fine in a shell, but when I boot I got an import error for zmq package, here's the cronlog:
Traceback (most recent call last):
File "/home/elachere/Documents/mg_app/r_server.py", line 7, in <module>
import zmq
ImportError: No module named zmq
I saw many posts about this, so far I tried :
-exports PYTHONPATH in my bash_profile and run the python script via a bash script
-add these lines to my python script (before zmq import):
#!/usr/bin/python
import sys
sys.path.append('/home/elachere/.local/lib/python2.7/site-packages/zmq/')
-set PYTHONPATH at the top of my crontab
Unfortunately nothing worked, I still get the import error.
Thanks in advance for your response.
I installed mod_python, I try to run python script like:
from mod_python import apache
It show me the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from mod_python import apache
File "D:\Python27\lib\mod_python\apache.py", line 55, in <module>
import _apache
ImportError: No module named _apache
I don't know why?
My enviroment:
Windows XP, Python 2.7.2
If you don't get any help here, try the mod_python mailing list:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/installation.html
Its probably that the script location is not added to your path.
try:
import sys
sys.path
sys.path.append('/path/to/the/mod_python.py')
If this doesn't work, it was probably not installed correctly.
If you want to add it to your system path permanently so you don't have to use the code above every time check out this SO question.
Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.