Bad Marshal error -- runsnake - python

I ran cProfile on a python 3 script, worked nicely, then tried to visualize it using runsnake. Howvever, I got an empty screen and the error 'bad marshal data'.
I removed .pyc file but that did not work either.
The code I used to install runsnake was:
sudo apt-get install python-profiler python-wxgtk2.8 python-setuptoolD
sudo easy-install installSquareMap RunSnakeRun
I am using UBUNTU.
Many thanks.
note: I should add I installed everything while py3k was activated

TL;DR: This error occurs when profiling in Python 2.x and viewing the profile in Python 3.x or vice versa.
I had the same problem. As far as I can tell, the RunSnakeRun package has not been ported to Python3. At least, I could pip it to python2 but not to python3 (SyntaxError). Further, I think the output format of cProfile is not compatible between python 2/3. I did not take the time to find an definitive confirmation of this, but in the doc of cProfile class pstats.Stats(*filenames, stream=sys.stdout), they do say "The file selected by the above constructor must have been created by the corresponding version of profile or cProfile. To be specific, there is no file compatibility guaranteed with future versions of this profiler, and there is no compatibility with files produced by other profilers.". This seems to be the origin of your problem. For e.g., I made a profile output from python3
import cProfile
cProfile.run('some code to profile', 'restats')
and tried to open it in RunSnakeRun and got the same marhsal error you got. Further, if I do
import pstats
p = pstats.Stats('restats')
p.strip_dirs().sort_stats(-1).print_stats()
in python3, it works like a charm. If I do it in python2, it gives the marshal error. Now, RunSnakeRun is executed in python2 (unless you found some way to make it run in python3). So, my guess is that you have performed your profiling in python3 and are using tools relying on python2 to analyze them, which tools are expecting the output to be compatible with python2.
The RunSnakeRun project seems to be inactive for a while now (copyright on the home page is 2005-2011) and there is no indication that it will be ported to python3.... Maybe considering alternative visualization tool might be the best way to go for you if you want to develop in Python3. pyprof2calltree in combination with KCachegrind worked fine for me in Linux. It can provide a similar visual view of the profiling output as you would get from RunSnakeRun.

Also ran into the same problem and I think there's no (good) way to use runsnake for Python3 (as it already was mentioned in the previous answer). However, SnakeViz might help. It's a relatively intuitive graphical overview of profiling data that, like runsnake, builds on top of profile outputs. Nice bonus: works also for Jupyter notebooks!

Related

How to get my Vim and MacVim to find python3?

When I use a plugin that requires python, it can't find it and barfs.
The places that seem to being searched are:
Using -version I see both:
+python/dyn
+python3/dyn
However :echo has("python3") returns 0.
I'm not sure if this is compile time config, or runtime-configurable via .vimrc.
I'm not a python developer, and the few times I've ventured into that world were in the middle of the python2/python3 mess that turned me off completely. I've played around enough to have configured pyenv it seems, and get
╰─$ which python
/Users/benlieb/.pyenv/shims/python
╰─$ python --version
Python 3.10.3
Can anyone help shed light on what to do to get python3 findable/usable in my vim?
Update:
Following #romainl's suggestion below I set in my .vimrc
set pythonthreedll=/Users/benlieb/.pyenv/shims/python
But getting the following error:
+python/dyn and +python3/dyn are described here: :help python-dynamic.
By default, :help 'pythonthreedll' points to:
/opt/homebrew/Frameworks/Python.framework/Versions/3.10/Python
because MacVim is built against that version. The message in your screenshot says that there is nothing at that path. In order to have a working Python 3 interface, you can either:
install Python 3.10 via homebrew,
or point pythonthreedll to a valid path.
For example, I don't use Homebrew so the default value is useless to me, but I use MacPorts so this is my pythonthreedll:
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
After some time, I found the following works, thought it was not a fun path of discovery.
let &pythonthreedll = trim(system("pyenv which python"))

How to solve incompatibility between DeepPavlov, Tensorflow and Numpy in a Python script

I am trying to run a script in Python 3.7 that makes use of DeepPavlov and Tensorflow==2.4.1.
It seems that there is an incompatibility, because:
DeepPavlov can work only with Numpy==1.18
Tensorflow==2.4.1 needs at least Numpy==1.19.2
If I downgrade Tensorflow, some of the instructions in the script fail, in particular I can not import "transpose_shape".
I may try to change the script, and use different functions.
However, I know for sure that this script has been successfully used by the person who gave it to me.
Is there a way around this apparent incompatibility?

Trying to run python code on jenkins in ubuntu

all.
I recently started working with Jenkins, in an attempt to replace cronjob with Jenkins pipeline. I have really a bit knowledge of programming jargon. I learned what I learned from questions on stackoverflow. So, if you guys need any more info, I would really appreciate if you use plain English.
So, I installed the lastest version of Jenkins and suggested plugins plus all the plugins that I could find useful to python running.
Afterwards, I searched stackoverflow and other websites to make this work, but all I could do was
#!/usr/bin/env python
from __future__ import print_function
print('Hello World')
And it succeeded.
Currently, Jenkins is running on Ubuntu 16.04, and I am using anaconda3's python (~/anaconda3/bin/python).
When I tried to run a bit more complicated python code (by that I mean import pandas), it gives me import error.
What I have tried so far is
execute python script build: import pandas - import error
execute shell build: import pandas (import pandas added to the code that worked above)
python builder build: import pandas - invalid interpreter error
pipeline job: sh python /path_to_python_file/*.py - import error
All gave errors. Since 'hello world' works, I believe that using anaconda3's python is not an issue. Also, it imported print_function just fine, so I want to know what I should do from here. Change workspace setting? workdirectory setting? code changes?
Thanks.
Since 'hello world' works, I believe that using anaconda3's python is not an issue.
Your assumption is wrong.
There are multiple ways of solving the issue but they all come down to using the correct python interpreter with installed pandas. Usually in ubuntu you'll have at least two interpreters. One for python 2 and one for python 3 and you'll use them in shell by calling either python pth/to/myScript.py or python3 pth/to/myScript.py. python and python3 are in this case just a sort of labels which point to the correct executables, using environmental variable PATH.
By installing anaconda3 you are adding one more interpreter with pandas and plenty of other preinstalled packages. If you want to use it, you need to tell somehow your shell or Jenkins about it. If import pandas gives you an error then you're probably using a different interpreter or a different python environment (but this is out of scope here).
Coming back to your script
Following this stack overflow answer, you'll see that all the line #!/usr/bin/env python does, is to make sure that you're using the first python interpreter on your Ubuntu's environment path. Which almost for sure isn't the one you installed with anaconda3. Most likely it will be the default python 2 distributed with ubuntu. If you want to make sure which interpreter exactly is running your script, instead of 'Hello World' put inside:
#!/usr/bin/env python
import sys
print(sys.executable) # this line will give you the exact path to the interpreter
print(sys.version) # this one will give you the version
Ok, so what to do?
Well, run your script using the correct interpreter. Remove #!/usr/bin/env python from your file and if you have a pipeline, add there:
sh "/home/yourname/anaconda3/bin/python /path_to_python_file/myFile.py"
It will most likely solve the issue. It's also quite flexible in the sense that if you ever want to use this python file on a different machine, you won't have your username hardcoded inside.

Visual Studio Code adding lines between code in Python terminal causing syntax errors

I'm running Python code in VS Code (1.28.2, with the Python, and Python Extension Pack extensions) and am using the 'Run Selection/Line in Python Terminal' (Shift+Enter) functionality to just run selected code in the Python terminal.
This has always worked well, but today I'm getting a new line added between each line of code in the terminal, i.e. if I ran:
import heapq
import pickle
the output in the terminal would be:
>>>import heapq
>>>
>>>import pickle
At first, this just seems like an annoyance, but any for loops or functions now come out with an indentation error...so essentially I can't successfully run any code.
I've tried re-installing VS Code as well as installing an older version of VS Code but all give the same problem.
It's so odd because it was working fine and then all of a sudden it changed. The only thing I can think of that has possibly changed is I installed the JSON Tools extension, but I don't believe this would change anything within Python (and I've tried uninstalling this, and not loading it again when reinstalling VS Code from scratch)
Any help would be greatly appreciated!
It's a bug that will be fixed in the 2018.9.1 release of the Python extension.

Error using gnuplot from within Sage, but works fine in regular Python

I apologize if this isn't the best place to ask this question, but hopefully someone here can help. I want to run some gnuplot commands directly from within a Sage script, but I get the following error message:
dyld: Library not loaded: /opt/local/lib/libfreetype.6.dylib
Referenced from: /opt/local/bin/gnuplot
Reason: Incompatible library version: gnuplot requires version 14.0.0 or later, but libfreetype.6.dylib provides version 10.0.0
This message appears if I try to use the gnuplotpy interface in Sage, or if I just use something like os.system("gnuplot -e \"plot('sin(x)')\"") from Sage. However, the same os.system(...) command works just fine in regular python. Many thanks.
Sage changes a number of environments including PATH, LD_LIBRARY_PATH, etc. This can cause problems running binaries not installed inside Sage. For this reason it provides a shell command sage-native-execute which (mostly) changes all the variables back. So try the following—it fixes the problem for me:
os.system('''sage-native-execute gnuplot -e "plot('sin(x)')"''')

Categories