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.
Related
I have a custom python script which sends emails, when I created it in Thonny and ran it all works fine.
However when I try to run it at start up or in the terminal I get the following error:
sudo python sendcpuwarning.py
Traceback (most recent call last):
File "sendcpuwarning.py", line 2, in
import sendmail
File "/home/pi/Scripts/sendmail.py", line 4, in
from email.message import EmailMessage
ImportError: cannot import name EmailMessage
Anyone know why this is happening?
Worked it out, the issue was I was calling python /script/location instead of python3 /script/location.
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 want to run a bash script by using ProcessBuilder. This is my xtend code:
new ProcessBuilder().inheritIO().command("/bin/bash", "-c", "./myscript.sh")
This is my bash script:
#!/bin/bash
python WebRoot/result.py
And the python code:
#! /usr/bin/env python
import rospy
from std_msgs.msg import Empty
...
The problem is that I get an error:
Traceback (most recent call last):
File "WebRoot/result.py", line 2, in <module>
import rospy
ImportError: No module named rospy
However, when I run the code manually via terminal, it works fine.
When you run it command line, you are probably getting a different environment from when it's running in your JVM. In your bash script, try pointing directly to the python version you intend to use. It's entirely possible that the JVM's env is pointing to a different version of python. Or that the environment is not fully setup.
Try to put the full path, like this, for example:
#!/bin/bash
/usr/bin/python2.7/python WebRoot/result.py
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]
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.