CentOS Python multiple interpreters issue - incorrect shebang - python

I'm trying to run a Python script (testing.py) as a cron job. I have CentOS with a separate python2.7 interpreter path, so I've added the following shebang:
#!/usr/local/bin/python2.7
However, when the cron job runs I get the following error
Traceback (most recent call last):
File "/root/carsales/carsales_v2.py", line 3, in <module>
import pandas as pd
ImportError: No module named pandas
I have installed Anaconda, and if I run the python2.7 interpreter through the command line, as:
python2.7 testing.py
It imports pandas successfully. However, running it directly (as per below) fails to import:
./testing.py
So there's some problem with the shebang, or possibly with the Anaconda install?

Related

How to add additional libraries in ExecuteStreamCommand in Nifi?

I'm not able to run a Python script from ExecuteStreamCommand.
These are the processor properties:
Command arguments: /home/directory/test.py
Command path: /bin/python3
Working directory: /home/directory
Error message: Traceback (most recent call last): File "/home/test.py", line 1, in import nipyapi ModuleNotFoundError: No module named 'nipyapi'
The way that I am able to get ExecuteStreamCommand processor to run python scripts with imported modules is to install the imported modules on the actual machine itself. Therefore, this means running pip or pip3 install {insert module name} on the command prompt for each system that this processor is running on.

Problem importing a specific library with python 2.7.10

I am trying to install the following package in my MacOS High Sierra 10.13.6:
https://github.com/Michalychforever/CLASS-PT
When i run the make file everything looks to work fine. It not only generate an executable, which i can run by terminal using the ./ command, but also a python wrapper. The problem is related only with the former.
When i try to import the library i get the following message:
import classy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/thiagomergulhao/Library/Python/2.7/lib/python/site-packages/classy.so, 2): Symbol not found: _zdotu_
Referenced from: /Users/thiagomergulhao/Library/Python/2.7/lib/python/site-packages/classy.so
Expected in: flat namespace
in /Users/thiagomergulhao/Library/Python/2.7/lib/python/site-packages/classy.so
I am using the built-in python version (i.e 2.7.10). I already installed the Xcode 10.1 together with command line commands. My .bash_profile is:
export PATH="/Users/thiagomergulhao/Library/Python/2.7/bin:$PATH"
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Does anyone have any ideia what is causing this problem?

Executing python script with selenium with batch (selenium error)

I'm trying to execute a python script with selenium module via batch file.
The python script itself runs perfectly OK, but when I try to execute the script through a .bat file it gives me the error 'ModuleNotFoundError: No module named 'selenium''
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:/Temp/chromedriver.exe')
driver.get('http://www.example.com')
C:\Python\Python37\python.exe C:\PythonTest\testFile.py
The error printed is:
Traceback (most recent call last):
File "C:\Users\ElGregory\PycharmProjects\PythonTest\testFile.py", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
Which obviously is a Python error, but when the code is run in Pycharm it runs as expected. (=selenium installed correctly)
Any help apreciated.
This could be because when you are running inside Pycharm, the libraries are installed in your virtual python environment (venv).
Either activate the virtual environment before running the python file for which you can read more at https://docs.python.org/3/library/venv.html
Or install your libraries globally

Running bash/python script with ProcessBuilder

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

python import from gdbinit doesn't work

I have installed python-opencv and I can run import cv2 and check version without problems from a python shell.
When trying to source this python file in gdb to provide a new gdb command I always get:
(gdb) source /opt/src/matrix-viewer/misc/matrix-viewer-gdb.py
Traceback (most recent call last):
File "/opt/src/matrix-viewer/misc/matrix-viewer-gdb.py", line 17, in <module>
import cv2.cv as cv
ImportError: No module named 'cv2'
My PC has got the sole python instance from Ubuntu distribution, why from gdb I'm getting an import problem regarding this just installed package that I'm able to load from a python shell.
EDIT
This is a python 2 package, and gdb loads python 3... Seems unsolvable.

Categories

Resources