libreoffice-code-highlighter icon indicating copy to clipboard operation
libreoffice-code-highlighter copied to clipboard

Code Highlighter extension for LibreOffice is not working on macOS High Sierra

Open maehne opened this issue 7 years ago • 7 comments

I tried to use the Code Highlighter extension with LibreOffice 5.4.2.2 on macOS 10.13 High Sierra. The extension installs without error. However, formatting source code fails, as the extension doesn't find pygments. LibreOffice.app on macOS has Python 3.5 embedded. Therefore, I tried to install it with the embedded pip3.5 version. However, this fails with the following errors:

$ sudo /Applications/LibreOffice.app/Contents/Resources/python /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/bin/pip3.5 install pygments
Password:
The directory '/Users/maehne/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/maehne/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygments
  Downloading Pygments-2.2.0-py2.py3-none-any.whl (841kB)
    100% |████████████████████████████████| 849kB 1.4MB/s
Installing collected packages: pygments
Exception:
Traceback (most recent call last):
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/sysconfig.py", line 419, in _init_posix
    parse_makefile(filename, g)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/sysconfig.py", line 288, in parse_makefile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/text_file.py", line 100, in __init__
    self.open(filename)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/text_file.py", line 115, in open
    self.file = io.open(self.filename, 'r', errors=self.errors)
FileNotFoundError: [Errno 2] No such file or directory: '/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/lib/python3.5/config-3.5m/Makefile'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 247, in move_wheel_files
    prefix=prefix,
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/site-packages/pip/locations.py", line 141, in distutils_scheme
    d.parse_config_files()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 386, in parse_config_files
    filenames = self.find_config_files()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 338, in find_config_files
    check_environ()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/util.py", line 179, in check_environ
    os.environ['PLAT'] = get_platform()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/util.py", line 103, in get_platform
    distutils.sysconfig.get_config_vars(),
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/sysconfig.py", line 482, in get_config_vars
    func()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/distutils/sysconfig.py", line 425, in _init_posix
    raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: invalid Python installation: unable to open /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/lib/python3.5/config-3.5m/Makefile (No such file or directory)

maehne avatar Oct 28 '17 21:10 maehne

Also, trying to install it by opening the .oxt file from the UI sends LibreOffice to 160% CPU use, no longer answering the system. Had to kill it.

fgm avatar Jan 16 '18 17:01 fgm

hi, I have solved the problem loading pygments in the right place. It seems LibreOffice uses a local distro of Python, so you should launch pip from inside a script of LibreOffice, i.e. something like this:

import pip
pip.main(['install', 'pygments'])

Take also a look at issue #10 .

max

maxmasetti avatar Feb 27 '18 15:02 maxmasetti

hi, I have solved the problem loading pygments in the right place. It seems LibreOffice uses a local distro of Python, so you should launch pip from inside a script of LibreOffice, i.e. something like this:

import pip
pip.main(['install', 'pygments'])

Take also a look at issue #10 .

max

I have Mac High Sierra Libreoffice 6.2

If open python shell from: /Applications/LibreOffice.app/Contents/Resources/python

and execute your code:

import pip
pip.main(['install', 'pygments'])

Obtain he error:

...
 invalid Python installation: unable to open /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/lib/python3.5/config-3.5m/Makefile (No such file or directory)

The Makefile is on /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.5/lib/python3.5/config-3.5m/Makefile not in the other folder

How can I resolve the problem?

masalinas avatar Oct 15 '19 12:10 masalinas

Hi, may be your user can't write/execute that directory and create/write the Makefile, due to its location: the /Application folder. As I suggested in issue #10, you should run python with root privileges (sudo):

$ sudo /Applications/LibreOffice.app/Contents/Resources/python 

maxmasetti avatar Oct 16 '19 14:10 maxmasetti

@masalinas try the following:

cd /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework
ln -s Versions/Current/lib lib
ln -s Versions/Current/include include
/Applications/LibreOffice.app/Contents/Resources/python

If you run into permissions issues when creating the symbolic links above you might want to prefix the commands with sudo.

And then run as suggested:

import pip
pip.main(['install', 'pygments'])

davidwinter avatar Oct 24 '19 22:10 davidwinter

@masalinas try the following:

cd /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework
ln -s Versions/Current/lib lib
ln -s Versions/Current/include include
/Applications/LibreOffice.app/Contents/Resources/python

If you run into permissions issues when creating the symbolic links above you might want to prefix the commands with sudo.

And then run as suggested:

import pip
pip.main(['install', 'pygments'])

this worked for me on macOS Catalina. thank you.

toko-stephen-leo avatar Nov 12 '19 07:11 toko-stephen-leo

I'm experiencing a problem here as well. I'm running OS X 10.11.6 with LibreOffice v 6.4.0.3.

So, when I attempt to install 'pygments' by invoking pip directly (as in the top of the first post in this thread) I get a completely different error.

sudo: unable to execute /Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/pip3.7: No such file or directory And yet I am confident there is no typo because I navigated to the file in the Finder and dragged the icon onto the Terminal window (which supplies the full path of the file properly formatted for the Terminal. I have no idea what that is about.

Then, I run into problems with the very last line with the command to install pigments.

I get this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'pip' has no attribute 'main'

(This is after I created the symbolic links...) I would guess that something in python may not be configured correctly or pip may not be installed properly. The easy_install command to install and/or upgrade pip produces a similar error.

All the files appear to be properly installed, and this is a fresh install of LibreOffice.

Perhaps the problem is that I'm not entirely sure what this means:

you should launch pip from inside a script of LibreOffice

I have interpreted it to mean that I need to run the command while running python which is contained in LibreOffice. However, it could also mean that I need to be running the LibreOffice app and somehow execute a script containing that command. However, I am not familiar with how to summon a console in LibreOffice and I don't know how else I could run a script in the app. So, I proceeded with the assumption that my first interpretation must be correct since the alternate interpretation seems impossible. But it's distinctly possible that this is my problem.

I'd be very grateful for any ideas, insight, pointers or assistance!

THANK YOU!

auralarch avatar Feb 21 '20 07:02 auralarch