Python script does get executed via SSH, but not on RPI itself - python

I created a GPS Script on my raspberry pi. It imports a couple of modules.
When I connect to the RPI via Visual Studio Code SSH, and execute: sudo python3 gpsd.py, the script starts. But when I try the exact same command on the local machine, I get a ModuleNotFound on the GPS and Alive_progress modules. Does anyone know what could be going wrong here?
from gps import *
from time import *
import time
import threading
import sys
from alive_progress import alive_bar
from datetime import datetime, date
import csv
from keep_alive import keep_alive
from gpiozero import CPUTemperature
import subprocess
import sys

You must have all these modules installed in your local I think

Related

Python3.8 Import Error No module name tqdm found

I'm trying to run this python project on my linux machine. I did setup everything according to the requirement but when I try to run the project with the ./generate.sh executable file I got the following error.
Import Error: No module name tqdm found.
Here are the imports exists in file.
import os.path as path
import ast
from glob import glob
import signal
import imp
import logging
import time
import numpy as np
import socket
import tqdm
import sys
import click
import tensorflow as tf
from tensorflow.python.client import timeline
I check with pip3 show tqdm command it shows me the package detail. I also try to uninstall and install again the project but got no luck.
If i remove the tqdm import from the file then it shows me this error.
File "./run.py", line 16, in <module>
import click
ImportError: No module named click
Can someone guide me what I'm doing wrong here?
it seems you are importing it wrong, from tqdm docs:
from tqdm import tqdm
I've checked it for both python2 and 3 and this is the way to use it.
The project you are trying to use at least 3 years old, so maybe things have changed since then, so if it wont work for you even with proper import statement you can simply remove it.
Every loop working with tqdm will work without it as well.
For example:
from tqdm import tqdm
for i in tqdm(range(10000)):
pass
is the same as:
for i in range(10000)):
pass

from GUI import *

I got this code in Python 2.7:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import logging
import math
import operator
import pickle
import re
import sys
import threading
import time
import unicodedata
from random import shuffle
import currencylayer
import quandl
import requests
from GUI import *
from arduinoSerial import *
from bs4 import BeautifulSoup
from ledDisplay import *
from timeout import timeout
When I run it an error occurs:
from GUI import *
ImportError: No module named GUI
I try to install GUI, but I couldnt:
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at '/home/in/PycharmProjects/untitled/venv/bin/python
Did I made somehting bad? Could someone help me?
Is there a module called "GUI" that you're trying to import?
Tkinter is the standard Python GUI framework. Maybe you're thinking of that, in which case you would need to use from tkinter import *.

Segmentation fault when importing libraries in Python

I am trying to import the following libraries in python:
import os, sys, random, glob, argparse, math, gc
import cv2
import dlib
import imutils
from imutils import face_utils
import matplotlib
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, exposure
import sklearn
from sklearn import svm, metrics
import numpy as np
import pandas as pd
from bcolz import carray
from tqdm import tqdm
from time import sleep
import datetime as dt
All these libraries are installed in a conda environment and working when I import them in a jupyter notebook.
However, when I try to import them in the terminal or using a script, as soon as I execute:
import matplotlib.pyplot as plt
There is a:
Segmentation Fault(core dumped)
I wonder why it works in jupyter notebook but not in terminal
Because anaconda is a virual envirounment and it works on the jupyter-notebook but not in your OS command line. If you want to use it on the command line, it is recommended to install python, pip and then the packages that you need (all on your command line).
I personally recommend to install pycharm IDE to test your code locally. It is really easy to install and it tries to recognize your python installation. There you can easily add all the packages you need in configuration and import them in the code.
Here is how to add packages (e.g.numpy) in pycharm
Select your Project in Pycharm navigation side
File > Settings ( Ctrl + Alt + s )
Project
Project Interpreter
Plus button
Search for Numpy
Install Package

Monitor file changes in windows xp issues in Python

I want to monitor if the file has been changed through using watchdog in Python, however, when I test, the terminal give me a warning,
"C:\Python27\lib\site-packages\watchdog\observers\__init__.py:89:UserWarning:Failed to import read_directory_changes. Fall back to polling.warning.warn("Failed to import read_directory_changes. Fall back to polling")"
I've installed pip to install watchdog, however, I still don't know how this problem occur.
here is the test code:
# coding=utf-8
import sys
import time
import logging
import urllib
import urllib2
import os
# import MySQLdb
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
print "hello"

Python Script unable to import installed modules when called as a subprocess

I've two Python scripts as given below
inner.py
#!/usr/bin/python
import os
import datetime
# <---- Some Code--->
main.py
#!/usr/bin/python
import os
import datetime
# <---- Some Code--->
subprocess.call(["/usr/bin/python",inner.py])
The problem is when the inner.py script is called from the main.py script it doesn't import any modules. For example it says
ImportError: No module named os
But when the script is executed standalone it works fine. Please help
The following works perfectly fine for me, and it's modified because some of your code seemed a little incomplete.
inner.py
#!/usr/bin/python
import os
import datetime
print os.getcwd()
main.py
#!/usr/bin/python
import os
import datetime
import subprocess
import sys
# <---- Some Code--->
subprocess.call([sys.executable, "inner.py"])

Categories