invalid elf header error for .so file - python

I'm trying to run a script in python, and I'm getting an "invalid elf header" error. I have a series of scripts that call one another, I'll go ahead and include those as well:
import sys
sys.path.append("/home/smh/Linux/Desktop/gras-03-03/python")
from python_utilities import GRASTestor
which calls GRASTestor.py
from BaseTestor import BaseTestor
import numpy as np
import hepunit as unit
from gdml_writer import gdml_writer
from GDMLGeometryBuilder import GDMLGeometryBuilder
from GRASMacroBuilder import GRASMacroBuilder,GRASRMCMacroBuilder
from Plotters import Plotter
import os
import sys
import SpenvisCSVFileHandler
which calls SpenvisCSVFileHandler.py
import string
import Spenvis.so
import os
from numpy import *
which is where we get our error, specifically with the line "import Spenvis.so"
/home/smh/Linux/Desktop/gras-03-03/python/python_utilities
Traceback (most recent call last):
File "perform_gras_rmc_tests.py", line 6, in <module>
from python_utilities import GRASTestor
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/GRASTestor.py", line 19, in <module>
import SpenvisCSVFileHandler
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/SpenvisCSVFileHandler.py", line 8, in <module>
import Spenvis.so
ImportError: /home/smh/Linux/Desktop/gras-03-03/python/python_utilities/Spenvis.so: invalid ELF header
And I'm not certain why it's not working. Any suggestions would be appreciated!

Never mind. Upon looking at the file architecture, it appears the file Spenvis.so is mac specific for some reason. Just need to get the correct file, then.

Related

I need help using ctypes on jython

I want to use libxmp.
I used:
import sys
sys.path.append('/usr/local/lib/python3.8/dist-packages')
which directly locate to libxmp
from libxmp import XMPFiles, consts
from libxmp.utils import file_to_dict
upper code box is the import part
I faced this problem:
Traceback (most recent call last):
File "/home/webprime/jython/jython/jython.py", line 5, in <module>
from libxmp import XMPFiles, consts
File "/usr/local/lib/python3.8/dist-packages/libxmp/__init__.py", line 37, in <module>
from ctypes import util
ImportError: cannot import name util
it works on Python 3.

ImportError: cannot import name 'scan_videos' from 'subliminal'

I'm using the module subliminal to easily retrieve subtitles from the internet.
The CLI works perfectly, but I cannot import it as a module in a .py file.
The simplest code ever:
import os
from subliminal import scan_videos
videos = scan_videos('./')
print(videos)
And I always have this error:
Traceback (most recent call last):
File "subliminal.py", line 2, in <module>
from subliminal import scan_videos
File "/Users/louisbertin/Desktop/videos/subliminal.py", line 2, in <module>
from subliminal import scan_videos
ImportError: cannot import name 'scan_videos' from 'subliminal'
I don't know what I'm doing wrong. I had copy-pasted the code from the documentation:
https://github.com/Diaoul/subliminal
Seems like you called your script subliminal.py, which makes Python find it instead of the installed module. Rename the script and you should be fine.

"Import Error: cannot import name 'unicode_literals' "

Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.
This is my code:
import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
pd.read_csv(rawData)
Here is the Error:
C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
File "FILEPATH/Main.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
from __future__ import division, absolute_import, print_function
File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'
Any suggestions for why this isn't working would be greatly appreciated.
You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:
import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
pd.read_csv(rawData)

Why is my Python program throwing an exception depending on the name of the file?

I'm just learning Python.
I have a file with the following content
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
If I name this file csv2.py and call:
python csv2.py
... it works. But if I name this file csv.py and run:
python csv.py
It triggers this exception:
C:\Git\algotrading [master ≡ +3 ~0 -0 !]> python csv.py
Traceback (most recent call last):
File "csv.py", line 2, in <module>
import matplotlib.pyplot as plt
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\collections.py", line 36, in <module>
import matplotlib.mlab as mlab
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\mlab.py", line 172, in <module>
import csv
File "C:\Git\algotrading\csv.py", line 2, in <module>
import matplotlib.pyplot as plt
AttributeError: module 'matplotlib' has no attribute 'pyplot'
It took me like 40 minutes to figure out the problem. I mean.. Figure out the problem had to do with the name of the file.
Why is that happening?
It looks like matplotlib.pyplot through various imports needs mlab.py which calls "import csv". This should find a file (that is not yours) called csv but since you have renamed your file to csv.py it is attempting to import that instead, overriding the required import and messing up the import for matplotlib.pyplot.
csv.py is built into python and thus is restricted.
If you run a python interpreter and try to import csv, you'll succeed without having to download anything new.
Like igoldthwaite and Daniel Dobalian said:
If you create a file named: csv.py with the content:
import csv
print(csv)
And run:
python csv.py
You will see that this file import itself:
<module 'csv' from '/home/your/folder/csv.py'>
Also, if you do the same thing with other modules, you will find the same result:
import subprocess
print(subprocess)
Result:
<module 'subprocess' from '/home/your/folder/subprocess.py'>
And finally, if you do it with a file named matplotlib.py, you will get the same result:
import matplotlib
print(matplotlib)
# <module 'matplotlib' from '/home/your/folder/matplotlib.py'>

Import Error: No Module Named Common - problems with py2exe

I have a script that starts like this with many imports:
from reportlab.graphics import shapes
from reportlab.lib.utils import ImageReader
from reportlab.graphics import barcode
from reportlab.lib.units import mm
from reportlab.pdfbase.pdfmetrics import stringWidth
import reportlab.rl_settings
import PIL
from cStringIO import StringIO
import labels
import pyodbc
import pandas
from os.path import expanduser
from time import sleep
import sys
I struggled massively with py2exe to even get an executable file. I finally managed it with the following setup script (most of which is just copy and pasted from similar issues and suggests on stackoverflow).
from distutils.core import setup
import distutils
import py2exe
import sys
import zmq
import os
sys.setrecursionlimit(5000)
distutils.core.setup(
options = {
"py2exe": {
"dll_excludes": ["MSVCP90.dll"]
}
},
)
sys.path.append('C:\\WINDOWS\\WinSxS\\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2')
packages=[
'reportlab',
'reportlab.graphics'
'reportlab.lib.utils'
'reportlab.rl_settings'
'reportlab.lib.units'
'reportlabl.pdfbase.pdfmetrics',
],
os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]
setup( console=[{"script": "working.py"}],
options={
"py2exe": {
"includes":
["zmq.utils", "zmq.utils.jsonapi",
"zmq.utils.strtypes"] } } )
I am sure my script is inelegant. It has three connected define functions and a final output.
try:
makeyourlabels()
except:
Print "Sorry, something went wrong."
I get an error when I run the file:
Traceback (most recent call last):
File "working.py", line 3, in <module>
File "reportlab\graphics\barcode\__init__.pyc", line 72, in <module>
File "reportlab\graphics\barcode\__init__.pyc", line 42, in _reset
File "reportlab\graphics\barcode\widgets.pyc", line 162, in <module>
File "reportlab\graphics\barcode\widgets.pyc", line 95, in _BCW
File "reportlab\lib\utils.pyc", line 243, in rl_exec
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: No module named common
If anyone can make any sense of all this and get my .exe running, I would be ever grateful!
As there is no testable code in the question I can not guarantee this will fix your issue but I can explain why you get this error. It is because py2exe didn't bundle reportlab.graphics.barcode.common into your .exe.
How do I know this, I followed the traceback to see what Reportlab was doing in the rl_exec call, it turns out it is make this call using exec:
from reportlab.graphics.barcode.common import I2of5
But because the import is only done dynamically py2exe doesn't know about the need for this package.
So how do you fix it? Simply add 'reportlab.graphics.barcode.common' to your package list, that should help py2exe locate the module it is looking for.

Categories