textmate / latex.tmbundle

TextMate support for LaTeX
97 stars 64 forks source link

Python interpreter on macOS 12.3 #190

Open schoeps opened 2 years ago

schoeps commented 2 years ago

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.

nimacodes commented 2 years ago

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.

schoeps commented 2 years ago

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)

nimacodes commented 2 years ago

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.

defjaf commented 2 years ago

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.

nimacodes commented 2 years ago

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

defjaf commented 2 years ago

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

schoeps commented 2 years ago

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

andreasloe commented 2 years ago

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

defjaf commented 2 years ago

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

defjaf commented 2 years ago

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?)

andreasloe commented 2 years ago

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 commented 2 years ago

(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.

nilsreiter commented 2 years ago

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.

dagnolo commented 2 years ago

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

vschiavoni commented 2 years ago

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

defjaf commented 2 years ago

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.

dagnolo commented 2 years ago

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

nilsreiter commented 2 years ago

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

dagnolo commented 2 years ago

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...

vschiavoni commented 2 years ago

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
sorbits commented 2 years ago

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: @.***>

vschiavoni commented 2 years ago

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

dagnolo commented 2 years ago

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

juandesant commented 2 years ago

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?

JackSteele commented 2 years ago

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.

sanssecours commented 2 years ago

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.

nilsreiter commented 2 years ago

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.

Bibi commented 1 year ago

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 commented 1 year ago

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

SdotVdot commented 1 year ago
/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?