Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interpreter on macOS 12.3 #190

Open
schoeps opened this issue Feb 2, 2022 · 30 comments
Open

Python interpreter on macOS 12.3 #190

schoeps opened this issue Feb 2, 2022 · 30 comments

Comments

@schoeps
Copy link
Contributor

schoeps commented Feb 2, 2022

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
Copy link

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
Copy link
Contributor Author

schoeps commented Mar 16, 2022

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
Copy link

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
Copy link

defjaf commented Mar 16, 2022

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
Copy link

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

@defjaf
Copy link

defjaf commented Mar 16, 2022

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
Copy link
Contributor Author

schoeps commented Mar 16, 2022

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

@andreasloe
Copy link

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

@schoeps schoeps changed the title Python interpreter on macOS 12.3 (beta) Python interpreter on macOS 12.3 Mar 17, 2022
@defjaf
Copy link

defjaf commented Mar 17, 2022

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

@defjaf
Copy link

defjaf commented Mar 17, 2022

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
Copy link

andreasloe commented Mar 17, 2022

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
Copy link

(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
Copy link

nilsreiter commented Mar 18, 2022

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
Copy link

dagnolo commented Mar 21, 2022

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
Copy link

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

@defjaf
Copy link

defjaf commented Mar 22, 2022

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
Copy link

dagnolo commented Mar 22, 2022

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

@nilsreiter
Copy link

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

@dagnolo
Copy link

dagnolo commented Mar 22, 2022

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
Copy link

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
Copy link
Member

sorbits commented Mar 22, 2022 via email

@vschiavoni
Copy link

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

@dagnolo
Copy link

dagnolo commented Mar 24, 2022

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

@juandesant
Copy link
Contributor

juandesant commented Mar 31, 2022

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
Copy link

JackSteele commented Apr 2, 2022

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
Copy link
Member

Commit 54d6709 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
Copy link

nilsreiter commented Apr 7, 2022

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
Copy link

Bibi commented Jan 27, 2023

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
Copy link

Bibi commented Feb 2, 2023

It seems the parsing issue is NOT related to python: see #198 (comment)

@SdotVdot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests