I have already looked at all of the suggested related questions, but none of them quite seem to have the answer to my problem.
I am trying to run an in-house legacy program on my 64-bit computer. The program I am trying to run is acmegui-64bit.so (there is also a acmegui.so), so it suggests that it was designed to be run on 64 bit machines. When I run it, I get
[tharpa#hpz44 bin]$ ./acmegui-64bit
:/dept/python32/lib:/usr/local/viz/notification/lib:/usr/lib
Traceback (most recent call last):
File "/dept/adapt/acme/py/acmegui.py", line 8, in <module>
import ACME, AcmeGui
File "/dept/adapt/acme/py/AcmeGui.py", line 10, in <module>
import AppShell, ACME, AcmeDialog, nwrSetup, nwwsSetup, nwrMaker, cwwsMaker, \
File "/dept/adapt/acme/py/nwrMaker.py", line 18, in <module>
import Config, Format, ACME, AcmeDialog, BusyTkDialog, nwrText, wxRoundup
File "/dept/adapt/acme/py/nwrText.py", line 16, in <module>
import ACME, Decoder, Config, Format, IdsDB, Product, Setup
File "/dept/adapt/acme/py/Decoder.py", line 12, in <module>
import ACME, Pils, Metar, SCD, SCP, WMOHeader
File "/dept/adapt/acme/py/Metar.py", line 6, in <module>
import ACME, acmedcd
ImportError: /dept/adapt/acme/py/Linux/acmedcdmodule.so: wrong ELF class: ELFCLASS32
[tharpa#hpz44 bin]$ ./acmegui-64bit
I have considered the possibility of converting acmedcdmodule.so to 64-bit. Is this possible? If not, how hard would it be to recreate it?
I have considered the possibility of converting acmedcdmodule.so to 64-bit. Is this possible?
No.
If not, how hard would it be to recreate it?
You would have to find sources for it and rebuild it. If the original program is available as open-source, this may not be too difficult. If it's closed-source, you'd have to contact original developer(s).
Before you go too far on this, you should check whether you already have a 64-bit version of acmedcdmodule.so (perhaps named acmedcdmodule-64bit.so). If you do, fixing this may be as easy as creating a few symlinks.
Related
This question already has answers here:
Circular import dependency in Python [duplicate]
(7 answers)
Closed last year.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Main\Programming\Python\Console\mod_project\auto_message_mod.py", line 5, in <module>
import mod
File "D:\Main\Programming\Python\Console\mod_project\mod.py", line 77, in <module>
main()
File "D:\Main\Programming\Python\Console\mod_project\mod.py", line 18, in main
main_program_menu()
File "D:\Main\Programming\Python\Console\mod_project\mod.py", line 36, in main_program_menu
auto.auto_message_tools()
AttributeError: partially initialized module 'auto_message_mod' has no attribute 'auto_message_tools' (most likely due to a circular import)
I keep getting these errors while I try to import the file call auto_message_mod.py into mod.py and in mod.py, I tried to call the function auto_message_tools(these files are in the same folder). I also have imported the other files into mod.py and it worked perfectly. Except auto_message_mod.py. I have written import auto_message_mod as auto but it was not working. I have already tried auto.auto_message_tools() but didn't work. Can someone please help me?
Python is a scripting language, which is interpreted line by line. An import statement literally means that it will jump into that file and start reading over it, before jumping back to the original file and continuing to read through that. Read more here.
You can see that in your traceback, you import a file, which then calls a function that is presumably in the original.
The best way to fix this is to separate import-time code from run-time code. That means everything should import before the code is run, meaning all your code outside your main file should be only found within functions and classes. That means that you are much less likely to create a circular import like this, since all the code will already be initialised before you call any of it.
If that doesn't work, experimenting with moving culprit import statements to the bottom often helps, although it is stylistically bad, so I'd only use it as a last resort.
My file is named "foo.py". It has only two lines.
import random
print(random.randint(10))
The error is...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 45, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
File "math.py", line 2, in <module>
from random import randint
ImportError: cannot import name randint
I am on MacOS 10.14.6
I note that I did not call random.randint() in this script, even
though it showed up in the error text.
I ran the script with $python
My /usr/bin/python is linked to python 2.7
I've tried this with python 3 as well, with the same error.
EDIT:
My script was originally named "math.py", but I changed it in response to another solution that pointed out the name conflict with the math.py library (even though my script was not importing that library). Even after my script name change, I'm still seeing --File "math.py"-- errors. Even after I'm no longer using random.randint(), I'm still seeing that function referenced in my errors.
I've tried deleting random.pyc and math.pyc to purge the artifacts of previous executions. But these do not see to eliminate the remnants of earlier errors.
Read the traceback:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py"
Python tries to do something inside the standard library random module...
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
in particular, it tries to import the standard library math module...
File "math.py", line 2, in <module>
but it gets yours instead (notice there's no path on the filename this time; it's just math.py in the current directory); i.e. the script you started from. Python detects the circular import and fails:
ImportError: cannot import name randint
Actually using randint doesn't matter, because this is a problem with the actual import of the module.
This happens because Python is configured by default (using sys.path, which is a list of paths to try, in order) to try to import scripts from the current working directory before looking anywhere else. It's convenient when you just want to write a few source files in the same folder and have them work with each other, but it causes these problems.
The expected solution is to just rename your file. Unfortunately there isn't an obvious list of names to avoid, although you could peek at your installation folder to be sure (or just check the online library reference, though that's not quite so direct).
I guess you could also modify sys.path:
import sys
sys.path.remove('') # the empty string in this list is for the current directory
sys.path.append('') # put it back, at the end this time
import random # now Python will look for modules in the standard library first,
# and only in the current folder as a last resort.
However, this is an ugly hack. It might break something else (and it can't save you if you have a local sys.py).
can someone help me?
Let me explain myself better.
I have this folder structure:
praw-test
jobs
__init__.py
redisJob.py
main.py
and if I run directly python jobs\redisJob.py it works just fine.
But, if I try to import the file redisJob.py in main.py it gives me this error:
File ".\main.py", line 13, in <module>
from jobs.redisJob import DailyJob
File "D:\git\praw-test\jobs\redisJob.py", line 5, in <module>
import praw
File "D:\git\praw-test\env\lib\site-packages\praw\__init__.py", line 14, in <module>
from .reddit import Reddit # NOQA
File "D:\git\praw-test\env\lib\site-packages\praw\reddit.py", line 5, in <module>
from update_checker import update_check
File "D:\git\praw-test\env\lib\site-packages\update_checker.py", line 11, in <module>
import requests
File "D:\git\praw-test\env\lib\site-packages\requests\__init__.py", line 53, in <module>
major, minor, patch = urllib3_version
ValueError: not enough values to unpack (expected 3, got 1)
Just to make sure, the import command is
from jobs.redisJob import DailyJob
Did I do something wrong?
Update
I found a workaround.
I just need to import urllib3 in my main.py then assigning the correct version.
import urllib3
urllib3.__version__ = '1.21.1'
from jobs.redisJob import DailyJob
These three lines have to be on top of my script.
It appears that you're importing under a different environment. Different launch techniques can spawn different processes and shells; this could lead to the environment variable having a value other than expected.
I don't know enough SDE details to give you a definitive solution, but I can certainly recommend a simple debugging line. Just before the problem line, insert
print urllib3_version
See what you get for the value in each launch method. I expect that there's some implementation detail, such as the values being concatenated somehow, or having some missing.
You can work around this with a check:
if len(urllib3_version) == 3:
major, minor, patch = urllib3_version
else:
# This will depend on what you see in the single value
You may need to split a string, supply defaults for missing values, or some other adaptation.
I've found that I need to install 'glue' first.
But after that, this error is still there.
Traceback (most recent call last):
File "C:\Users\Saisa\Desktop\Code\python\myWebSpiderForPixiv_top100.py", line 1, in <module>
from gwpy.timeseries import TimeSeries
File "C:\Users\Saisa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\gwpy\timeseries\__init__.py", line 27, in <module>
from .core import *
File "C:\Users\Saisa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\gwpy\timeseries\core.py", line 45, in <module>
from ..data import (Array2D, Series)
File "C:\Users\Saisa\AppData\Local\Programs\Python\Python35-32\lib\site-packages\gwpy\data\__init__.py", line 29, in <module>
from glue.lal import (Cache, CacheEntry)
ImportError: No module named 'glue.lal'
Here is another idea of what you could try:
If I understand right, your directory hieracy looks something like this:
\root
\glue
\lal
\other
\another
and in lal there are the functions and classes and whatever you want. Is lal a directory or a file? If it is a directory, I don't understand why It is not working, I just wrote a analogue code and for me it worked perfectly. Maybe ther error is somewhere entierely else, sh*t happens in python, too. But if it is a file like lal.py you don't have to tell from glue.lal import (whatsoever)! This whatsoever are functions then in one file. Just type from glue import lal, it will import everything in there.
Your Problem is that Python does not know where to find the module. You must add the path to the Path Browser where the module code is saved in and then you can use the
import themoduleyouwant
Or
from themoduleyouwant import *
command.
You can find the Path Browser under "File >> Option >> Path Browser"
Usually, it will show you the standard libraries and your current working directory (cwd). So if you are looking for a quick solution, just take the directory of 'glue' and copy+paste it into your cwd.
Result: The Error will disappear.
I'm following some online python tutorials and i ran across this syntax error code twice now and can't figure out what's wrong.
Here's my code:
import urllib
import re
htmlfile = urllib.urlopen("http://finance.yahoo.com/q?s=AAPL")
htmltext = htmlfile.read()
regex = '<span id="yfs_l84_aapl">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern, html)
print price
I am using Enthought Python Distribution package (python version 2.7.3)
Here's the syntax error when i run the above script.
Traceback (most recent call last):
File "E:\python\scripts\stocks.py", line 4, in <module>
htmlfile = urllib.urlopen("http://finance.yahoo.com/q?s=AAPL")
File "e:\python27\lib\urllib.py", line 86, in urlopen
return opener.open(url)
File "e:\python27\lib\urllib.py", line 207, in open
return getattr(self, name)(url)
File "e:\python27\lib\urllib.py", line 291, in open_http
import httplib
File "e:\python27\lib\httplib.py", line 79, in <module>
import mimetools
File "e:\python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "e:\python27\lib\tempfile.py", line 34, in <module>
from random import Random as _Random
File "E:\python\scripts\random.py", line 1
def random
^
SyntaxError: invalid syntax
I tried searching around to understand what's going on but no avail. What's python trying to tell me with all these traceback lines and why do I get a syntax error?
If you look at the stack trace, towards the bottom, you can see that the syntax error is in a file called E:\python\scripts\random.py. This script is one you've added to the system, and it appears to contain a syntax error. Because it's named random and is located in the Scripts directory, it is "overriding" the built-in random library.
Remove or rename that file and you should be good to go.
The import of module is controlled by sys.path. To a first approximation when your program executes import module the interpreter visits the directories on sys.path in turn. It looks for a module.pyc file and a module.py file in each directory, moving on to the next if it finds neither. When it finds one or both, if the .py is newer than the .pyc (in other words, if the source has been modified since the file was last compiled, or if the compiled file does not exist) then the interpreter compiles the .py file and attempts to write to it. There are no guarantees your process will be able to write in that particular directory.
Having identified the correct file the interpreter creates a new namespace, executes the code of the module with that namespace as local, then binds the name of the module with the namespace just created. So if you have bound a name in module it should (modulo any __all__ assignment in the module's code) be available within your importing module as module.name.
I suspect this question has taught you why it's not a good idea to duplicate the names of system libraries in your own code - a lesson we all have to learn!