Open maxmasetti opened 7 years ago
I have the same problem in macOS Mojave and I don't have much experience on Python:
Message: <class 'ImportError'>: No module named 'pygments' (or 'pygments.styles' is unknown)
I checked Python 2.7.10 is already installed in /usr/bin/python
Things I've tried but no luck:
sudo pip install pygments
sudo easy_install pygments
Are there any simple installation instruction like using Homebrew?
ok, may be you have not pip or a second version (3). Open the console and type pip, than type tab twice: it shows you all the resolution for that string, for me:
max$ pip⟶⟶
pip pip-2.7 pip-autoremove pip2 pip2.7 pip3 pip3.7
max$ pip
Then use pip2.7:
max$ sudo pip2.7 install pygments
Actually pip could be linked up to pip3.7, for me it is:
max$ pip -V
pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
max$ pip2.7 -V
pip 19.0.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
But if the tab don't show up any pip command, you don't have it installed yet. So install it first and than install pygments. To install pip you can use easy_install:
$ sudo easy_install pip
$ sudo pip install --upgrade pip
Yes I have pip2.7 installed, sudo pip2.7 install pygments
shows:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/Users/fur/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.
WARNING: The directory '/Users/fur/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.
Requirement already satisfied: pygments in /Library/Python/2.7/site-packages (2.4.2)
So it seems to be already installed successfully, but in LibreOffice still showing the same error:
A Scripting Framework error occurred while running the Python script vnd.sun.star.script:codehighlighter.oxt|python|highlight.py$highlight_csharp_default?language=Python&location=user:uno_packages.
Message: <class 'ImportError'>: No module named 'pygments' (or 'pygments.styles' is unknown)
File "/Applications/LibreOffice.app/Contents/Resources/pythonscript.py", line 1047, in getScript
mod = self.provCtx.getModuleByUrl( fileUri )
File "/Applications/LibreOffice.app/Contents/Resources/pythonscript.py", line 484, in getModuleByUrl
exec(code, entry.module.__dict__)
File "/Users/fur/Library/Application Support/LibreOffice/4/user/uno_packages/cache/uno_packages/lu345742p3ox5.tmp_/codehighlighter.oxt/python/highlight.py", line 19, in <module>
from pygments import styles
File "/Applications/LibreOffice.app/Contents/Resources/uno.py", line 425, in _uno_import
raise uno_import_exc
File "/Applications/LibreOffice.app/Contents/Resources/uno.py", line 347, in _uno_import
return _builtin_import(name, *optargs, **kwargs)
ok, here is the problem: this trhead is about OpenOffice. Actually OpenOffice uses macOs Python installation, while LibreOffice don't. It uses a custom install of Python just inside the .app package. I wrote the same instruction for LibreOffice in the referenced issue, let's have a look at #14 too. You should launch Python from inside LibreOffice.app
$ sudo /Applications/LibreOffice.app/Contents/Resources/python
and then execute these lines of code
>>> import pip
>>> pip.main(['install', 'pygments'])
hi, this extension works in OpenOffice on macOS Sierra too but you need to install pygments in the right python environment. Actually I've some python installed while OpenOffice uses the official macOS one, i.e. python 2.7, so in the console type pip and then to tab key twice to obtain all the pip available, for me is pip-2.7. Now you can install pygments with a command:
and all works fine. In case of dubt, you have to modify a python script like HelloWorld.py located in the folder /Applications/OpenOffice.app/Contents/share/Scripts/python and add before return
Than execute HelloWorld from Writer to see where the OpenOffice python loads imports and particulary where is site_packages located. From that info you should find the right python and pip. hope this helps. max