latex.tmbundle icon indicating copy to clipboard operation
latex.tmbundle copied to clipboard

Python interpreter on macOS 12.3

Open schoeps opened this issue 3 years ago • 30 comments

Apple will finally drop python 2 in macOS 12.3. It's already missing in the current beta. Unfortunately, there is no binary /usr/bin/python but only /usr/bin/python3. Therefore this workflows fails although being python3 compatible (since #111). However, manually correcting the python path in the first line (hash-bang) works for me.

schoeps avatar Feb 02 '22 16:02 schoeps

Could you advise in which file you are changing the python path? I have the the python environment variable TM_PYTHON in TextMate, but unfortunately this does not seem to work.

nimacodes avatar Mar 16 '22 12:03 nimacodes

I manually changed the hash-bang from #!/usr/bin/python to #!/usr/bin/python3 in the *.py-files in ~/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/...

(by the way: I hope the maintainers will fix this soon since 12.3 is out)

schoeps avatar Mar 16 '22 12:03 schoeps

Thanks, I changed the hash-bang but now it seems my homebrew python installation go messed up :D At least it is now finding the interpreter.

nimacodes avatar Mar 16 '22 13:03 nimacodes

I am now on Monterey 12.3 and /usr/bin/python has disappeared as expected. I have tried replacing /usr/bin/python with /usr/bin/python3 throughout the bundle -- and it doesn't work. I get errors like ModuleNotFoundError: No module named 'Foundation'.

However, using /usr/local/bin/python2 does work. On my machine, this is actually a link to a build in /Library/Frameworks/Python.framework/Versions/2.7/bin/; I am embarrassed to say I don't remember where this came from -- possibly python.org! But I suspect not all users will have it.

defjaf avatar Mar 16 '22 16:03 defjaf

I followed @schoeps advise, changed all references from python to python3 and installed pyobjc package. Now TextMate works as a charm again.

nimacodes avatar Mar 16 '22 16:03 nimacodes

I wrote:

I have tried replacing /usr/bin/python with /usr/bin/python3 throughout the bundle -- and it doesn't work. I get errors like ModuleNotFoundError: No module named 'Foundation'.

But @nimacodes wrote:

I ... changed all references from python to python3 and installed pyobjc.

Which is indeed the solution. In particular: /usr/bin/python3 -m pip install pyobjc

defjaf avatar Mar 16 '22 17:03 defjaf

Sorry. I forgot to mention that you need pyobjc. I had it already installed :)

schoeps avatar Mar 16 '22 17:03 schoeps

Unfortunatively, this does not work for me. I installed pyobjc, updated textmate (and my MacOS as well) and get the following error messages if I run LaTeX (cmd-R) Traceback (most recent call last): File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/bin/texmate.py", line 1014, in status = command_parser.parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 771, in parse_stream return super(LaTexMkParser, self).parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 188, in parse_stream function(matching, line) File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 790, in start_latex fatal_error, number_errors, number_warnings = parser.parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 611, in parse_stream return super(LaTexParser, self).parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 195, in parse_stream line = self.get_rewrapped_line() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 140, in get_rewrapped_line line = to_utf8(self.input_stream.readline()) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 128: invalid continuation byte

andreasloe avatar Mar 17 '22 10:03 andreasloe

Weird. Do you have any weird characters in your document? Can you run latex on that file outside of TM?

defjaf avatar Mar 17 '22 14:03 defjaf

Perhaps it's worth forking this bundle into a version with the hardcoded python3? Is there any way to force installation of pyobjc or at least give a useful message to users? (How did it work with the old python2 installation? Was pyobjc installed by Apple?)

defjaf avatar Mar 17 '22 14:03 defjaf

Weird. Do you have any weird characters in your document? Can you run latex on that file outside of TM? I can run the file outside (using textstudio). I just checked a simple "Hello World" example and this wen through. Only skim shows an error Found 0 errors, and 0 warnings in this run 165:183: syntax error: Die interne Tabelle ist übergelaufen. (-2707) (internal table overflow). So this has to do with encoding?

andreasloe avatar Mar 17 '22 17:03 andreasloe

(How did it work with the old python2 installation? Was pyobjc installed by Apple?) It worked smooth, very smooth. pyobic was not installed, I just installed today.

andreasloe avatar Mar 17 '22 17:03 andreasloe

Thanks for posting this! I followed the above (adjust the shebang, install pyobc) and the compilation now works fine, but syntax highlighting not (fork here). The LaTeX.plist file looks fine, but within TextMate, the bundle editor displays the corresponding grammar as empty.

nilsreiter avatar Mar 18 '22 15:03 nilsreiter

I followed the suggestions above (change python to python3 in the .py files) and now TextMate indeed compiles in latex. However, it complains when I try to change the latex preferences (I need to change the pdf viewer since TextMate does not support synctex). This is the error message:

Failure running “Preferences…”. Preferences…: /Users/xxx/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/bin/configure.py: /usr/bin/python3: bad interpreter: Operation not permitted

Any further help? Thanks

dagnolo avatar Mar 21 '22 14:03 dagnolo

Also hitting this problem, hopefully this gets fixed soon. Thanks !

vschiavoni avatar Mar 22 '22 09:03 vschiavoni

I haven't seen any of the issues since

  1. Changing /usr/bin/python to /usr/bin/python3 everywhere in the bundle.
  2. Running /usr/bin/python3 -m pip install pyobjc

I did briefly see the syntax highlighting issue, but it went away after restarting textmate.

Hint: make sure that you make the python -> python3 change everywhere. I changed it in:

  1. Commands/Lines to List Environment.tmCommand
  2. Support/bin/configure.py
  3. Support/bin/texdoc.py
  4. Support/bin/texmate.py
  5. Support/bin/texparser.py
  6. Support/lib/Python/itemize.py

Note that the first one isn't python source, but an xml file.

defjaf avatar Mar 22 '22 09:03 defjaf

Thanks! (In fact I previously missed to modify files 1 and 6 of your list)

dagnolo avatar Mar 22 '22 09:03 dagnolo

Hmm, I've missed the tmCommand file, but fixing that didn't fix the syntax highlighting issue. I'm thankful for other ideas :)

nilsreiter avatar Mar 22 '22 12:03 nilsreiter

Hmm, I've missed the tmCommand file, but fixing that didn't fix the syntax highlighting issue. I'm thankful for other ideas :)

I agree... It worked for me on an old Mac, but not on a newer one in my office...

dagnolo avatar Mar 22 '22 13:03 dagnolo

To do 1) from @defjaf suggestion, I had to:

plutil -convert xml1 "Commands/Lines to List Environment.tmCommand"
(..do the edit..)
plutil -convert binary1 Commands/Lines\ to\ List\ Environment.tmCommand

vschiavoni avatar Mar 22 '22 13:03 vschiavoni

You don’t need to convert it back to binary. This is only to keep the size of bundle deployments/updates down.

On 22 Mar 2022, at 14:48, Valerio Schiavoni wrote:

To do 1) from @defjaf suggestion, I had to:

plutil -convert xml1 "Commands/Lines to List Environment.tmCommand"
(..do the edit..)
plutil -convert binary1 Commands/Lines\ to\ List\ 
Environment.tmCommand

-- Reply to this email directly or view it on GitHub: https://github.com/textmate/latex.tmbundle/issues/190#issuecomment-1075203132 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

sorbits avatar Mar 22 '22 13:03 sorbits

In any case, the steps mentioned above from @defjaf worked for me on a new macbook pro M1 with macOS 12.3.

vschiavoni avatar Mar 22 '22 14:03 vschiavoni

My fault, sorry. It now works also for me.

dagnolo avatar Mar 24 '22 10:03 dagnolo

The pull request #191 above would resolve this issue for everyone, it would be great if it could be approved… any maintainers for this repository?

juandesant avatar Mar 31 '22 21:03 juandesant

I just made a similar PR in javascript.tmbundle, but it's been years since any have been approved. Having just found this, I am less optimistic.

JackSteele avatar Apr 02 '22 02:04 JackSteele

Commit https://github.com/textmate/latex.tmbundle/commit/54d6709ba450d341e0f3d01c930f900c115f8ba8 should hopefully improve the current situation a little bit. On macOS 12.3 or later you still need to install PyObjC, using Terminal (or a similar application):

/usr/bin/pip3 install pyobjc

before you can use commands that depend on Python though. I tested the changes on macOS 11.6.5 and 12.3.1. At least translating a very small document with “Typeset & View (PDF)“ seems to work correctly. At the time of writing the new code is not yet part of the official Bundle index. This should (probably) be the case in the next days.

sanssecours avatar Apr 03 '22 11:04 sanssecours

I finally solved my syntax highlighting problem, but without fully understanding it. It has nothing to do with Python, but I'll describe it here because of the context.

Situation: In the bundle editor, all language grammars are there, except "LaTeX": It shows an empty pane with two curly braces { }. The file LaTeX.plist is there and readable and plutil has no complaints about it.

Solution: What finally fixed it was to change the UUID of the grammar file (after converting it to xml). Suddenly, everything works as expected. I tried to find if some other bundle is using the same, but didn't find anything in all my installed bundles.

nilsreiter avatar Apr 07 '22 11:04 nilsreiter

Unfortunatively, this does not work for me. I installed pyobjc, updated textmate (and my MacOS as well) and get the following error messages if I run LaTeX (cmd-R) Traceback (most recent call last): File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/bin/texmate.py", line 1014, in status = command_parser.parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 771, in parse_stream return super(LaTexMkParser, self).parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 188, in parse_stream function(matching, line) File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 790, in start_latex fatal_error, number_errors, number_warnings = parser.parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 611, in parse_stream return super(LaTexParser, self).parse_stream() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 195, in parse_stream line = self.get_rewrapped_line() File "/Users/andreasloeffler/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/Python/parsing.py", line 140, in get_rewrapped_line line = to_utf8(self.input_stream.readline()) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 128: invalid continuation byte

@andreasloe Did you solve this problem? I seem to experience the same issue...

Bibi avatar Jan 27 '23 15:01 Bibi

It seems the parsing issue is NOT related to python: see https://github.com/textmate/latex.tmbundle/issues/198#issue-1568227275

Bibi avatar Feb 02 '23 15:02 Bibi

/usr/bin/pip3 install pyobjc

It is not always recommended to meddle with the python that already comes installed with the system. Therefore, would it be possible for the bundle to link with the python indicated in the environment variable?

SdotVdot avatar Sep 24 '23 16:09 SdotVdot