Using Vim to edit R-script: why Python keeps complaining - python

I am very new to R, and should only have two plugins that get loaded specifically for *.R scripts: jalvesaq/Nvim-R and vim-pandoc/vim-rmarkdown. However, I shall see the following error message every time I open an *.R file:
The problem when I open an R-script
On a MacBook Air (through MacVim):
On a Windows machine (Gvim):
I would need to click on the Reopen button for once; and the Close program button for twice. Afterwards, the Nvim-R plugin runs with no problem.
Possible solution?
Can I possibly get ride of these warnings? And/or, should this be a Vim-Python support problem? When starting the python-mode plugin, I get a Windows R6034 runtime error.
I have no trouble using other plug-ins that also calls Python, including: VOom, vim-tex and

Partial solution on Windows platforms
To delete all existing Python and Vim distribution;
To install a 64-bit Python (my version that worked is Python 2.7.14)
To install a 64-bit built Gvim (I found it from Cream, build Vim 8.0-1123)
Sanity check
Open a Vim with the following plug-ins loaded: Nvim-R, klen/python-mode.
To open a *.R file
To open a *.py file
Pending solution on Mac OS X
Also asked a question through the Mac-superuser forum: https://apple.stackexchange.com/questions/302213/how-to-properly-use-macvim-on-os-x-and-to-delete-the-duplicative-app-via-fi

Related

Error "tcgetpgrp failed: Not a tty" using python3 to open web browser

Here's the breakdown of my Windows WSL environment:
Windows 11
WSL version 2
Ubuntu version 20.04.3 LTS
Python 3.8.10
I have a super simple Python program I'm using to open a web page in my default browser.
Here is my code:
import webbrowser
webbrowser.open('https://github.com')
When I run this from my terminal the webpage opens up as expected, but I also get this error in the terminal:
tcgetpgrp failed: Not a tty
When my terminal displays this message, the cursor goes down to the next line and it looks like a process is hung or something. To be able to use the terminal I have to Ctrl+C to get it to give me the command prompt.
I looked for answers and everything I could find has to do with using Jupyter or PHP but I'm not using either of them, I'm just using plain old Python to try and open the browser.
Can anyone tell me what the issue is here and how to fix this/prevent it from happening?
Yes, I can also reproduce it from the Python (and IPython) REPL on Ubuntu under WSL. I don't get the "lockup" that requires Ctrl+C when running interactively, at least.
I'll theorize on the "why". Most of this I can confirm myself, but the last bullet below is still a bit of a mystery to me:
webbrowser-open uses whatever browser is defined by the BROWSER environment variable first, but falls back to (I believe) xdg-open.
xdg-open uses whatever browser is defined in the alternatives system for x-www-browser or www-browser.
On Ubuntu 20.04 on WSL, the wslu package is installed by default (it is no longer a default package under 22.04, though).
That package includes the wslview helper. From its manpage:
[wslview] is a file viewer on WSL that allows you to open files and folders from WSL in Windows and a fake web browser that allows opening urls in your default browser on Windows 10.
wslview is registered during the wslu installation as the alternative for both x-www-browser and www-browser.
webbrowser.open doesn't just call xdg-open, but it attempts to get the process information of the resulting browser so that it can (at the least) raise the window if requested. Part of this is obtaining the process group via, apparently, the tcgetpgrp system call. According to the tcgetpgrp manpage:
The function tcgetpgrp() returns the process group ID of the foreground process group on the terminal associated to fd, which must be the controlling terminal of the calling process.
Here's where I have to "hand-wave" a bit -- Something in the hand-off from webbrowser.open to wslview to binfmt_misc (the kernel system that allows it to launch Windows executables) is "losing" or redirecting a file descriptor of the terminal, resulting in this message.
It appears to me to be a bug (unintended side-effect?) of wslview, since making sure it isn't used will prevent the error from occurring.
As a workaround, either:
export BROWSER=/mnt/c/path/to/windows/browser before starting Python. Note that I'm not sure how to point to Edge, since it's there's no ".exe" for it that I'm aware of (it's a Universal/Modern/UWP/whatever app).
Or, since you are on Windows 11, install a Linux browser. I used Vivaldi to test and confirm that it opened properly from Python under WSL. Note that you can't sudo apt install either Chromium or Firefox under WSL since they are both Snaps.

How to get Pygame script to run on macOS

I have a rather small Pygame based python script and I just bought a Mac so I'm trying to run my script on here. Everything has been installed correctly (Checking by typing 'import Pygame') into python terminal as-well as running a basic hello world program. However, when I try running this script, IDLE gets brought to the front but nothing happens from there. (The script is supposed to pop-up a new window). Is this a problem with my installations or my code? (Code works on windows setup).
You could try to run the script again on a windows computer to see if you forgot to save some changes or if the file got corrupted somehow. You could also use bootcamp to install Windows on your mac since you could have one windows version on your mac for coding purposes and the regular mac OS for other stuff if you like.
you can execute it by left clicking in your script and select open with python launcher

IDLE 3.4.3 crashes when running module

I've recently started to use Python, and I don't know much about programming.
I've installed Python 3.4.3 in my Mac OS X Yosemite, and it worked fine for a few months, but now every time I want to run a module it stops responding.
so I use IDLE and when I open a new file to define a function I can write, then I click run and I save my file, and then when I click save IDLE doesn't restart as it use to and I can't write on it or do anything else. there is no crash report, no nothing, just all frozen. I close it and if then I re open and write on IDLE it works but as soon as I try to run a new file again it freezes.
How can I solve it?
to try stuff out i've been using repl.it online and it is useful for a learner like me but still I would like to be able to use IDLE on my mac.
THANK YOU FOR YOUR HELP!!!!
Try using Anaconda, which is another Python distribution, but more science-oriented. It has all the commonly required modules already in it (plus other for scientific purposes), so that you don't have to install them as and when required. And when you install Anaconda, it automatically installs Spyder, which is a much better IDE than IDLE.

Problems installing IDLE2HTML

I'm trying to install IDLE2HTML from the following link in order to print from IDLE in color. I use Python 2.7 on a Mac.
I follow the instructions from the readme.txt, but when I reload IDLE nothing has changed. I don't have the Save As HTML option.
In the past I've installed and reinstalled Python a few times.
When trying to find my idlelib folder (as written in the readme instructions), I eventually found it under the path /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
Is my problem that my python is in /System/Library/?
Any ideas please?
I have not tried this extension, but the following may help. When you start Idle, select File / Path browser on the menu. You should see
_ sys.path
|
+ some_path/pythonxy/Lib/idlelib
|
+ some_path/python27.zip # or MAC equivalent
The first path tells you where the new files should be. If you click the +, you will see what file are there. What about IDLE2HTML.py? The next issue is whether you properly edited config-extensions.def. If you wait a few days for 2.7.9 and install it, you can try the new Options / Config-extensions dialog on the menu. That will show whether Idle can read the new information in the .def file. Or you can edit your question, paste in the new material you added, and comment on this answer, and I will take a look. However, given that the extension has been around for years, I presume that the addition in config-extensions.txt is correct.
I suspect that whenever you upgrade Python, config-extension.def will be overwritten and you will have to re-edit it.
If the problem is not a configuration problem with the IDLE2HTML Python IDLE extension like this answer (for the same question) explains about, it may be a problem with the code itself (this has happened with Python 3 IDLE). This can be checked by running IDLE using the Python file that starts it (<PYTHON LIBRARY DIR>\idlelib\idle.py where <PYTHON LIBRARY DIR> is the location of the standard library for the Python installation), in a command line interpreter (use <PYTHON EXECUTABLE DIR>\python.exe where <PYTHON EXECUTABLE DIR is the location of the executable files that start Python). It will launch IDLE and show any errors in the C.L.I..
Quote from Python idlelib module docstring:
Idle includes an interactive shell and editor. Use the files named idle.* to start Idle.
IDLE2HTML real error example:
A common problem is that IDLE2HTML version 2.0 (latest at time of writing) needs a simple code tweak to work with Python 3.x (a fixed version that works as part of the IDLEX Python module had this tweak). File comparison image (left is original file, right is IDLEX version in image); if the Python version is Python 3.x, import Tkinter needs to be changed to import tkinter as Tkinter and import tkFileDialog needs to be changed to import tkinter.filedialog as tkFileDialog:
Edwards suggestion of using the CLI for diagnosis was very useful. It exposed that the cgi.escape attribute does not exist for Python 3.
I changed the IDLE2HTML.py line 74 from "out.append(cgi.escape(content))" to
"out.append(content)" and after a re-boot it all worked!
Later: well almost... better to replace "import cgi" with "import html and then cgi.escape() with html.escape()
If using Win10 you will need super-admin rights to change IDLE2HTML.

Hard times with IDLE

So I've been working with Python on my computer for about the last 2 months with no issues. Just recently however, something went wrong with IDLE. I am running python 2.5
I used to be able to right-click and select "Edit with IDLE" for a python program. That option no longer is available. When I try "open with" and navigate to the idlelib in python, I can select idle.bat, idle.py, or idle.py (no console). I've tried each option and each fails to open and returns an error that either it is not a valid Win32 application or that "Windows cannot find idle.pyw"
I am able to open IDLE on its own and use the open function in IDLE to open files, but can't open files directly using IDLE as I could before.
There was formerly the White background icon with the python logo, which is now replace by windows' logo for no program (white square, blue and red dots). I have tried to repair-install and unistall-re-install both with no success. There is no firewall or antivirus, and it was installed with permissions for all users.
Any help is much appreciated, this has been maddeningly difficult to figure out.
The native one that comes with python on windows is problematic at times, so you could uninstall and reinstall it as a solution, or open it from its directory instead of a shortcut, or get another IDE. I recommend the Ninja IDE very nice and light looking, or if you're on linux you could just use vim from terminal.
Also, if it's extremely necessary, try upgrading your python version and IDE. I think the IDE included for windows looks like a modified emacs to be honest.
The fact that Windows changed the right-context menu for .py files has nothing to do with Idle, and probably nothing to do with Python either. You are not the first to have this problem. You can potentially restore 'Edit with Idle' but without directly editing the registry (an expert option) I only knew how to do so in XP. You might also be able to fix it be going back to a restore point before it changed, but you would lose all updates since, so I would not do that.
I am surprised that re-installing did not restore it. The line was once gone for me, too, and was restored by a recent install.
I have Win7. I just now tried 'Open with', navigated to 3.4 idlelib, and selected idle.bat (the .py files were not offered as a choice). The .py file opened in an Idle editor just fine. It is now a permanent option for Open with, without having to navigate.
Idle has gotten perhaps 150 patches since 2.5. Even if you have to edit programs to run on 2.5, I strongly recommend installing a current version of Python and Idle.
I have no ideal what your comment "the programs still can't find anything associated with it, like Tkinter for example " means.

Categories

Resources