This a conceptual question. What reasons could motivate that a script runs successfully on Spyder IDE but not directly in Python. I am in Win7-64x. I think it is because Spyder is somehow more lenient.. maybe it uses hidden modules, libs, bats..? I found this problem when I was trying to make an executable using Pyinstaller, so I step back and check running the myscript.py on python directly like this on cmd,
python myscript.py
and it runs the script but throws normal errors like "list index out of range". The thing is they don't appear if executed inside the Spyder IDE, the script in Spyder is run fine without errors. I don't know the possible reasons. There is a way to roundabout that for pyinstaller, so that the produced executable runs fine like in Spyder? Suggestions? (Win7-64x, Python3.6, Spyder3.3.3)
Related
i have matlab script which using few matlab libraries like Map ToolKit. I can run this script on MATLAB without any error. But i need to run this with QGIS and get output files.
Simply, script asks few question about Map Tools and get like .shp files and give output folder.
So to get these output files, i tried 3 ways:
I tried to run this code on Python Console. For that i installed matlab.engine and called script just like in documentation. But these matlab.engine doesn't let python to use matlab's own libraries so error on using shapeinfo function. It just let python to use few variables i think. So after failing on this i tried second way:
I created executable matlab file to run .exe file on python console. In here, there is a two way to get this exe file. First one is let you smaller file and doesn't include matlab runtime so you need to add matlab runtime on your path and i did it. Actually Matlab does that as default and i checked that it was okey. Executable file runs perfectly after clicking or on normal python scripts which is running on through CMD. But if i call Python Script in QGIS, it trying to open but returns Matlab runtime dll missing error. After i tried to compile with matlab runtime selection and results were same.
Lastly, i tried to run matlab.exe -r "try, run SCRPIT_PATH\script.m; end; quit on CMD and it works fine but if i call this on QGIS Python Console with os.system or subprocess.call functions, cmd appearing and closing immediately.
I guess QGIS doesn't let you to open some other applications somehow and i need to let it run. Or i just need to find import matlab libraries to python for work perfectly. I would be pleasure if you give any suggestion. Any solution for these ways or a different way would be great. Thanks.
I am trying to compile a .tex file in a Python script using pdflatex. The command pdflatex filename.tex works when I run it from the command line on Windows. However, attempting to run os.system("pdflatex filename.tex") just spits out 1 into the Python console and does not compile a pdf. I've also tried putting in the full file path similar to this person solved their problem but the same thing happens. Similarly, subprocess.call(['pdflatex', 'filename.tex']) just outputs a 1 and does not do anything.
It seems someone else has encountered the same problem in this thread, but on Mac instead of Windows. (But regardless of the operating system, they didn't find an answer.)
Why might this be happening?
EDIT: I've just discovered a solution. The script runs successfully (using the os.system approach) when I run the .py file using the command line. Previously I was attempting to run the script from RStudio, both using reticulate::source_python(filename) and also line-by-line via the reticulate REPL. Seems like the problem may actually be coming from R's reticulate package rather than anything to do with Python.
Fortunately RStudio has a terminal window so this doesn't end up being too inconvenient!
I often use the python breakpoint() command as a way of debugging code or for changing the values of variable on-the-fly. This works great when I launch a python script from the (windows) console, as breakpoint() lets me type commands in that console.
My question is how do I do achieve something similar when running a python script launched some other way? For example, when I package my code into an .exe with PyInstaller (with the no-console option to keep it tidy) and launch the .exe, breakpoint() does nothing at all. I know one way to remove this problem is to compile the .exe without the no-console option, but I'd rather have it there as it just keeps everything clean. A similar problem also arises when running a python script via a os.execl() call in another.
Is there someway of making the code launch its own console whenever breakpoint() is called, and having that console control the debugging commands? I suspect that this is possible through manipulating the PYTHONBREAKPOINT variable, but I don't know how, or where to start looking.
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 :)
I am trying to stop execution of Python scripts in IPython in Windows. I have installed Python and IPython using Anaconda. However, whenever I press Ctrl+C, it breaks out of the current Python script as well as IPython. I saw a similar post here, which said to instead launch IPython with python C:\python27\scripts\ipython-script.py (or wherever that .py script is located), but for Anaconda users that script is in C:\Users\andre\Anaconda3\pkgs\ipython-5.1.0-py35_0\Scripts\ipython-script.py (which then changes with every version number if IPython that is installed). This ends up working but is certainly not convenient. I can make a quick shortcut/keybinding that runs that ipython-script.py script, but if and when I update IPython, I'm going to have to change the shortcut, and that seems rather inconvenient.
Any suggestions? I suppose I could add C:\Users\andre\Anaconda3\pkgs to my path, but that seems a little bit of overkill since there are a ton of packages in there.