How to run this .py script correctly? - python

I downloaded a program called "A ren'py script decompiler," and I cannot for the life of me work out how to run it.
I googled a bit to discover that the files I had downloaded, which were in ".py" format, referred to Python, (yes, this is the level I am on,) so I downloaded it, and after a bit more googling, managed to run the script.
However I have still no idea how to get this thing to actually do what I want, as when I try to copy the commands from the README, it just brings up errors, and half the time I don't even understand what the README is saying in the first place. For example: "You can either use the -b argument to specify the directory in which renpy lies or place the renpy module in your Python module search path." This is gibberish to me.
So I know this is a big ask, but apparently getting this to run is supposed to be pretty simple -- it's just a lightweight program/script/thing that decompiles .rpyc scripts. So does anyone know how I can get it to work?
This is the thing: https://github.com/yuriks/unrpyc
When I run the script in Python it just says:
usage: unrpyc.py [-h] [-c] [-b BASEDIR] [-d]
[--python-screens | --ast-screens | --no-screens | --single-line-screen-kwargs]
file [file ...]
unrpyc.py: error: too few arguments
And then after that I don't know what to type to get it to work anyways.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
--basedir
NameError: name 'basedir' is not defined

I'm the maintainer of unpryc
The script should be ran with python 2.7. Also I'm glad to tell you that in the more recent version of the decompiler (http://github.com/CensoredUsername/unrpyc) the dependency on renpy has been removed, so you no longer have to fiddle with the --basedir option.
regarding the error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
--basedir
NameError: name 'basedir' is not defined
I'd guess that's caused because you're trying to run the command in a python shell instead of a normal command prompt. If you want to call the script normally open a command prompt (I think you're on windows, so it'd be cmd.exe) and run the command:
path_to_python_executable unrpyc.py script_you_want_to_decompile.rpyc
path_to_python_executable is usually C:\Python27\python.exe
That should work.

You won't need most options; the only one you probably need is the -b switch, and of course the script you want to decompile.
The -b (or --basedir) option tells this script where to find the Ren'Py source code; you need to have that program installed too, and then give the directory where it's Python modules are located to this script. Presumably just downloading the SDK, extracting that somewhere and naming that path with teh -b switch is enough:
unrpyc.py -b /path/to/renpy/modules/directory script_you_want_to_decompile.rpy

Related

Darknet attribute error on Windows. Something wrong with the DLL?

I am attempting to run a python file, darknet_video.py (or any python file) on Windows 10.
While running on linux I have had no problems using the .SO in exactly the same way. However, I am forced to have to port this to Windows and use the DLL.
I have compiled yolo_cpp_dll.sln with Visual Studio 17. No errors. On the command line, I can invoke darknet with, say,
./darknet.exe detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights -thresh 0.25
The above works.
What does not work is the following:
python.exe darknet_video.py --data_file cfg/coco.data cfg/yolov3.cfg/yolov3.weights ..
With the above I get the following
Traceback (most recent call last):
File "darknet_video.py", line 119, in
network, class_names, class_colors = darknet.load_network(
AttributeError: module 'darknet' has no attribute 'load_network'
This type of error is the same no matter what kind of a python file I use.
I am certainly not an expert in using Windows DLLs but if I had to guess I would say that somehow the DLL was compiled in such a way that it can not understand calls such as "load_network" or any other type of call that is made.
How to proceed?
Thank You
Tom
If you compiled yolo_cpp_dll.sln correctly you
would get yolo_cpp_dll.dll then in darknet.py
change lib= CDLL('whatever') to
lib = CDLL("yolo_cpp_dll.dll", RTLD_GLOBAL).

Python Script not Running - Has to be something simple

OS: Fedora 21
Python: 2.7.6
I run a python script as root or using sudo it runs fine. If I run it as just the user I get the following:
Traceback (most recent call last):
File "/home/user/dev_ad_list.py", line 12, in
import ldap
ImportError: No module named ldap
selinux=disabled -- What other security is preventing a user from running a python script that imports ldap
If it works fine under sudo, it simply sounds like a file access issue.
A quick fix for this would be to run something along the lines of:
sudo chmod -R a+rX /usr/lib/python2.7
But you may wish to be more specific with the directory (or even file) that you actually apply this to.
Path to python was different than other user. User was pointing to canopy.

Bash alias not working for Python script

Trying to set a Bash alias in order to run a Python script for Pygame.
I have the android.py acript in, /usr/local/bin/pgs4a-0.9.6/andoid.py.
Bash alias: alias pyg='python /usr/local/bin/pgs4a-0.9.6/android.py'
When I run python android.py when I am in the folder in executes just fine, but when I do it from any other folder or using the alias, I get the following error.
pyg
Traceback (most recent call last):
File "/usr/local/bin/pgs4a-0.9.6/android.py", line 11, in <module>
import interface
ImportError: No module named interface
Can anybody explain to me why this is?
Try this:
alias pyg='PYTHONPATH=/usr/local/bin/pgs4a-0.9.6 python /usr/local/bin/pgs4a-0.9.6/android.py'
That is, set your $PYTHONPATH environment variable to contain the directory with the code. You may need to adjust the PYTHONPATH to some other location, depending on where your interface package actually resides.

Why is PYTHONPATH being ignored?

I am setting PYTHONPATH to have a directory that includes a few .py files.
When I go into python and type "import file", the file cannot be find (it says "No module named wsj10").
If, however, I cd to the directory, and repeat the same process, then the file is found.
I am just not sure why PYTHONPATH is being ignored. I followed exact instructions from installation instructions of some software, so I know I am doing the right thing.
Any circumstances under which PYTHONPATH will be ignored, or import won't work?
Thanks.
Following a comment below, here is a transcript:
untar file1.tgz to file1/. file1.tgz contains a library/file called file1.py.
type in the shell:
export PYTHONPATH=`pwd`/file1/:./
echo $PYTHONPATH shows the variable was set.
run python and type "import file1"
I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named file1
If I do first "cd file1" and then to import file1 it identifies the file.
Any circumstances under which PYTHONPATH will be ignored, or import won't work?
Yes. I've set PYTHONPATH in my /home/me/.bashrc and all worked ok from terminal, but when Apache w/ mod_wsgi starts my python scripts, it acts under sysem or dedicated user, which knows nothing of my .bashrc.
For this particular situation, I just used apache config to set python path for apache (WSGIPythonPath option).

python gtk module opens display on import

I'm using the trick "python -c 'import myscript.py'" to perform a syntax check on a script which uses 'import gtk'.
I get the following error when performing the syntax check, which implies that the gtk module is executing a check for the X display, even though all that's being done at this point is to import the module.
Traceback (most recent call last):
File "<stdin>", line 15, in ?
File "myscript.py", line 21, in ?
import gtk
File "/usr/src/build/463937-i386/install/usr/lib/python2.3/site-packages/gtk-2.0/gtk/__init__.py", line 37, in ?
RuntimeError: could not open display
Is there a way to avoid this error when performing the syntax check?
Before you ask - I'm not able to set $DISPLAY before the syntax check is run. The check is being run on remote servers as part of a distributed build system. These servers do not have an X display available.
Importing modules in Python executes their code!
Well-behaved modules use the if __name__ == '__main__' trick to avoid side effects, but they can still fail - as happened to you.
[BTW, getting to ImportError means the whole file already has correct syntax.]
If you just want to check syntax, without running at all:
python -m py_compile my_script.py
will check one file (and produce a .pyc as a side effect).
python -m compileall ./
will check a whole dir recursively.
python -c 'compile(open("myscript.py").read(), "myscript.py", "exec")'
avoids creating a .pyc.
But note that merely checking the syntax in Python catches very few bugs! Importing does catch more, e.g. mispelled names. For even better checks, use tools like Pychecker / Pyflakes.
What exactly do you mean by 'syntax checking'?
Can't you use a tool like pylint to check for syntax errors?
Otherwise: a very ugly (but probably possible hack):
In your python script detect whether X is present.
If it's not => use GTK on DirectFramebuffer (no X needed then). You'll need to compile GTK on DirectFB (and/or pygtk) from source (some pointers here).
If the remote machine has vncserver installed, you can have a dummy server running and connect to that. Sample instructions:
remotemachine $ vncserver -depth 16 -geometry 800x600 :7
New 'X' desktop is remotemachine:7
Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/userve:7.log
remotemachine $ DISPLAY=:7 python -c 'import myscript.py'
…
remotemachine $ vncserver -kill :7
Killing Xtightvnc process ID 32058
In your myscript.py, you could do like this
if __name__=="__main__":
import gtk
That will not execute gtk's __init__.py when you do "python -c 'import myscript.py'"
If you are editing with IDLE, Alt+X will check syntax of current file without running it.

Categories