Pyjamas-desktop (pyjd) compiles, runs and quits - python

I'm running Pyjamas on Windows 8.1 with Python 2.7 (64-bit). I've struggled a bit with getting everything installed, but I believe the struggle has been fruitful -- I've run bootstrap, the file "run_bootstrap_first_then_pyjd_setup.py", and have moved on to experimenting with Pyjamas DESKTOP.
I'm trying to view the Hello.py example (in the examples/helloworld directory) by running both a run.bat file in the command line & by double-clicking in the GUI Windows Explorer. The code of the .bat file is below:
#echo off
python Hello.py
The program will compile, run, open up a white window then immediately quit. Which makes me think it's not quite running (or that Pyjamas doesn't interface with Windows 8.1). If I run the Hello.py file directly by typing
python Hello.py
into the command line, the same thing happens.
I'm guessing this is a Windows software versioning problem (8.1 isn't capable of running the current version of Pyjamas or .....any ideas?

Haven't run into this particular error, but to help debug what is going on, you can try this:
python Hello.py
if errorlevel 1 (
echo Failure Reason Given is %errorlevel%
PAUSE
exit /b %errorlevel%
)
If you can, get an IDE that can have a running console of python. Here is an overly comprehensive list. Just quick browsing on the debugging column, I would say use Netbeans or PyDev with Eclipse.

Related

Spyder IDE 5.3.3 (Python 3.8) execution of TCL script hangs in Windows 10

I have a python script that runs without problems when I run it from the Windows command shell or Visual Studio 2019. When I run it in the Spyder IDE, executing the TCL script hangs. I'm using the following to run the TCL script:
subprocess.call("script.tcl")
Is that script running with tclsh or wish? Only the former really works properly as a subprocess thing on Windows because tclsh is built as a console program and terminates when the end of the script is reached, whereas wish is built as a GUI program and does not (it instead runs the event loop until the last window is closed).
The default binding for .tcl files on Windows is against wish. I'm not convinced that that's the right choice, but it's how it is.

Running python scripts from windows 10 execute line (WIN + R panel)

I am struggling with an apparently obvious issue. I've been practising python and I have a few scripts and I am trying to run them from windows 10 execute command (WIN + R).
I am doing this by creating a BATCH file of the script, and in theory the file should run with a simple "py script" in the WIN+R window. But it does not, it simply flashes the CMD window for a sec and then disappear.
Everything seems to be set up correctly, I can run the script from CMD, BATCH file are OK (they run with a double click, I included the #pause at the end), the folder where BATCH are is in the env. variables PATH.
So i really don't get what is wrong. Note that If I type the full path in the WIN+R window it works, but that takes quite some time..
Any hints?
A BIG thank you :)
EDIT: thanks for the replies, here is the batch:
#py script.py
#pause
It works on double click.
Ctrl + R => opens run window.
Type in "cmd"
If you have python installed with Path.
python <yourscript.py>
should run just fine.
Otherwise,
Run as below.
path/to/python/python.exe <yourscript.py>
Hope you did the same as above. If the bat runs and closes in a flash. That is not an issue. It happens.
Have a sleep in your bat as well. If you're running on bat.
Add below after your python script execution.
It will make your bat script wait for a thirty seconds before closing and you can verify your stdout.
timeout /t 30
On Windows, executing Python scripts directly, i.e. without calling python before, can be tricky. Often Windows will just open your default Python editor to show you the file, because the .py extension is registered to this editor.
see this post for more info:
How to execute Python scripts in Windows?
You should create a batch file as follows...
#py -3 E:\FOLDER\SUBFOLDER\FILE.py %*
#pause
I have both python 2 and python 3 so I use py -3 as for me py will run Python 2
The ending %* is important

In VS Code, can one run Python code in an integrated Python terminal like in Spyder?

Currently, in Visual Studio Code (under Windows 10 64bits), at a Python file called path\myfile.py, if one clicks with mouse right-button for context menu and then chooses 'Run Python File in Terminal', an integrated CMD terminal is open and file is automatically run there with:
python.exe path\myfile.py
After the file stops running, one is naturally left at the integrated CMD cursor.
This behavior is quite different, for instance, from what one has with an IDE like Spyder. There, when you run code (e.g. with F5), at the end one is left still at the Python cursor and can access content of variables created when code was run.
Is there a way to achieve a similar behavior in Visual Studio Code?
You can configure VS Code Python extension to use the -i command line option
Described in https://docs.python.org/3/using/cmdline.html#cmdoption-i
You only have to add the setting bellow (inside settings.json file)
"python.terminal.launchArgs": ["-i"],
This will execute the command python.exe -i path\myfile.py.
I don't know if it is a new feature, but I've been using it for while.
If you would like to use the terminal IPython, like in Spyder, you can use a different set of options, as the following:
"python.terminal.launchArgs": ["-m","IPython","-i"],
With these, VS Code will execute the command python.exe -m IPython -i path\myfile.py.
Then, it will run IPython module as a "script" (with -m option), which will use the options -i path\myfile.py, i.e., IPython will run the file and remain opened.
BTW, another thing is: you can run "cells" in Spyder's integrarted terminal (regions of code with #%%). But in VS Code it seems you can't.
I've made a question with a "work around" to run cells of Python files in VS Code Integrated terminal, which is posted Here
Yes. Open a terminal window and it's like a terminal window on your computer. You can type python filepathandname and the python script will execute like it does from the command line.
The closest you can come is to run the code under the debugger and set a breakpoint at the end to pause the exiting of the execution. Otherwise feel free to file a feature request at https://github.com/microsoft/vscode-python.

what can I do if a program can be run by python console while can not be run by ipython console?

It seems that the spyder has removed python console, but I got a program can only be run by python console, what can I do? or is there any thing I am wrong?
I got some codes from github, and it needs ADB driver for Android, after I installed ADB, I can run the program in cmd using python wechat_jump_auto.py, but cannot run in spyder with ipython.
In Spyder3 installed in Windows OS, we can add the path to adb using Tools --> Current user environment variables....
Here, we can add the path to adb.exe file by appending it to the path variable. Then, we need to restart Spyder3. Then you will be able to directly run your script with access to adb.exe from Spyder3 IPython console or simply by clicking Run button.
Just came across the same problem as you recently.
In fact, it seems that program using ADB tools just cannot run in Spyder even by python console (my Spyder IDE is equipped with both Ipython console and Python console).
One practical way to solve this problem is to run your code in cmd.
Open your cmd window and do something like this:
python "xxx(path)\xxxx.py(file name)"
In my case, it looks like this:
example image
Hit Enter, and hopefully your code will run successfully.
If it still cannot run, maybe you haven't set your environment variables correctly.
Hope this can solve your problem. Good luck :)

Executing python in windows via notepad (F6 Exec command __main__ error)

I have notepad++ installed on win7, and have installed the notepad++ exec plugin. Whenever I execute the .py script I am running, i get the following error:
C:/Python27/python.exe ""
Process started >>>
C:\Python27\python.exe: can't find '__main__' module in ''
<<< Process finished.
================ READY ================
My index.py script is as follows:
text = "Hello World"
print text
The Notepad++ execute script (F6) is as follows:
C:/Python27/python.exe "$(C:/Python27/python.exe)"
This is the correct path to python.exe on my system. In the windows environmental variables, I have also added this to the PATH. Also, I have booted up the python.exe command prompt and have gotten the script to work by manually typing it in. I have done a directory search of C:/Python27, and the main.py file exists.
What is going on that is wrong here? Why can't python find the __ main __ module??
EDIT:
Nevermind this, I'm an idiot.
So I had misinterpreted the setup for the notepad++ exec (F6) script:
C:/Python27/python.exe "$(C:/Python27/python.exe)"
It should have been this instead:
C:/Python27/python.exe "$(FULL_CURRENT_PATH)"
Of course it couldn't find the main.py file because it wasn't going to FULL_CURRENT_PATH.
Carry on.
Basically, it's because the 1st argument in your script has been missinterpreted.
That is to say, with the code
C:/python27/python.exe "$(C:/python27/python.exe)"
You're doing something roughly equivalent
C:/python27/python.exe
What you need to use is:
C:/Python27/python.exe "$(FULL_CURRENT_PATH)"
Note: Don't substitute "$(FULL_CURRENT_PATH)" for something else - put that in verbatim - it's a predefined variable of the NppExec plugin. It may be considered shorthand for the full-path of the file in the currently open tab.
When I execute the script above (on a file called tmp.py, in my c:\xampp\htdocs\enhzflep folder), I get this displayed in the console:
C:/Python27/python.exe "C:\xampp\htdocs\enhzflep\tmp.py"
CreateProcess() failed with error code 2: The system cannot find the
file specified.
Which is just fine, since I don't have python installed on this machine. :)
EDIT: Just saw your edit. It seems I'm the greater fool!

Categories

Resources