0

Symptoms: File is apparently being used:

File "/usr/lib/python2.7/dist-packages/salt/renderers/pyobjects.py", line 449, in render
 exec final_template in _globals, _locals
File "<string>", line 6, in <module>
File "/usr/lib/python2.7/dist-packages/salt/utils/pyobjects.py", line 293, in __getattr__
 raise AttributeError

Great. However when I go to /usr/lib/python2.7/dist-packages/salt/utils/pyobjects.py it isn't in that directory and none of its pyc's are there either:

ls /usr/lib/python2.7/dist-packages/salt/utils/py*
/usr/lib/python2.7/dist-packages/salt/utils/pydsl.py /usr/lib/python2.7/dist-packages/salt/utils/pydsl.pyc

Why is this happening? What am I missing about this -- I have tried searching and found nothing useful yet.

Update if this is any use:

$ python -v
>>> import salt.utils.pyobjects
# /usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.pyc matches /usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.py
import salt.utils.pyobjects # precompiled from /usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.pyc
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
asked Jan 13, 2015 at 12:03
4
  • you are running it in salt/renderers/pyobjects.py` whereas you are looking into salt/utils/pyobjects.py Commented Jan 13, 2015 at 12:07
  • Perhaps the .pyc file was moved elsewhere and that is now being imported, but the file recorded a full-path filename?. Run python -v and trace all imports. Commented Jan 13, 2015 at 12:07
  • @ha9u63ar: they are talking about the last line in the traceback. Commented Jan 13, 2015 at 12:07
  • You can only get the verbose output if at the time of import that file actually exists. So when that import takes place, both files are there, both /usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.pyc and /usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.py exist according to the OS and have a modification time and can be read. Commented Jan 13, 2015 at 12:20

1 Answer 1

1

The python -v verbose output you posted shows that the file is imported from a different location:

/usr/local/lib/python2.7/dist-packages/salt/utils/pyobjects.pyc
# ^^^^^

but you are looking in:

ls /usr/lib/python2.7/dist-packages/salt/utils/py*
# ^^^^

.pyc files store a filename in the bytecode, and the file must've been moved from /usr/lib to /usr/local/lib. So when a traceback is shown, the filename from the bytecode is still pointing to the old location.

You can force a re-compile (running with sudo or another means to gain write access) with:

python -m compileall -f /usr/local/lib/python2.7/dist-packages/salt

to produce .pyc files that store the new location.

answered Jan 13, 2015 at 12:22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.