How to install local python libraries in users home?

22 views
Skip to first unread message

Mo

unread,
Nov 7, 2019, 7:40:29 AM11/7/19
to Trac Users
Hi,

as mentioned in https://trac-hacks.org/ticket/13640 some Python libraries are not available by the Linux distribution, so I like to install them separately by pip.
How can I install for instance xhtml2pdf locally for the trac home in ~trac/ ?

I tried by

 pip install --user xhtml2pdf

and got

$ tree ~trac/.local/lib64/ -L 3
/mnt/data/trac/.local/lib64/
└── python3.6
   
└── site-packages
       
├── PIL
       
├── Pillow-6.2.1.dist-info
       
├── PyPDF2
       
├── PyPDF2-1.26.0-py3.6.egg-info
       
├── reportlab
       
├── reportlab-3.5.32.dist-info
       
├── xhtml2pdf
       
└── xhtml2pdf-0.2.3-py3.6.egg-info

But Trac still fails like this:
2019-11-06 11:22:22,359 Trac[loader] DEBUG: Skipping "TracWikiPrintPlugin 2.0.0.dev0": DistributionNotFound: The 'xhtml2pdf' distribution was not found and is required by TracWikiPrintPlugin

The uwsgi workers are running as user trac and should be able to find the python library at $HOME.

Jun Omae

unread,
Nov 7, 2019, 8:09:12 AM11/7/19
to trac-...@googlegroups.com
On Thu, Nov 7, 2019 at 9:40 PM Mo <burcheri...@gmail.com> wrote:
>
> Hi,
>
> as mentioned in https://trac-hacks.org/ticket/13640 some Python libraries are not available by the Linux distribution, so I like to install them separately by pip.
> How can I install for instance xhtml2pdf locally for the trac home in ~trac/ ?
>
> I tried by
>
> pip install --user xhtml2pdf
>
> and got
>
> $ tree ~trac/.local/lib64/ -L 3
> /mnt/data/trac/.local/lib64/
> └── python3.6
> └── site-packages
> ...

Cannot. Your system installed pip is targeted to Python 3.6. The pip
must be installed as targeted to Python 2.7.
I recommend to use virtualenv with Python 2.7 rather than using system
installed pip.

See https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS

--
Jun Omae <jun...@gmail.com> (大前 潤)

Mo

unread,
Nov 8, 2019, 4:03:17 AM11/8/19
to Trac Users
Am Donnerstag, 7. November 2019 14:09:12 UTC+1 schrieb Jun Omae:
Cannot. Your system installed pip is targeted to Python 3.6. The pip
must be installed as targeted to Python 2.7.
I recommend to use virtualenv with Python 2.7 rather than using system
installed pip.

See https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS

I already had:
 
 [I] dev-python/pip
     
Available versions:  9.0.1-r1^t (~)9.0.1-r2^t 19.1^t (~)19.3.1^t {test -vanilla PYTHON_TARGETS="pypy pypy3 python2_7 python3_5 python3_6 python3_7"}
     
Installed versions:  19.3.1^t(15:38:09 05.11.2019)(-test -vanilla PYTHON_TARGETS="python2_7 python3_6 -pypy -pypy3 -python3_5 -python3_7")

I found there is also pip2.7 and I did:

pip2.7 install --user xhtml2pdf

Now I have:
$ tree ~trac/.local/lib64/ -L 3
/mnt/data/trac/.local/lib64/
├── python2.7
  └── site-packages
      ├── PIL
      ├── Pillow-6.2.1.dist-info
      ├── PyPDF2
      ├── PyPDF2-1.26.0-py2.7.egg-info
      ├── reportlab
      ├── reportlab-3.5.32.dist-info
      ├── xhtml2pdf
      └── xhtml2pdf-0.2.3-py2.7.egg-info
└── python3.6
   
└── site-packages
       
├── PIL
       
├── Pillow-6.2.1.dist-info
       
├── PyPDF2
       
├── PyPDF2-1.26.0-py3.6.egg-info
       
├── reportlab
       
├── reportlab-3.5.32.dist-info
       
├── xhtml2pdf
       
└── xhtml2pdf-0.2.3-py3.6.egg-info

But even after restarting the uwsgi I get: 'xhtml2pdf' distribution was not found

Jun Omae

unread,
Nov 8, 2019, 5:09:32 AM11/8/19
to trac-...@googlegroups.com
On Fri, Nov 8, 2019 at 6:03 PM Mo <burcheri...@gmail.com> wrote:
> I found there is also pip2.7 and I did:
>
> pip2.7 install --user xhtml2pdf
>
> Now I have:
> $ tree ~trac/.local/lib64/ -L 3
> /mnt/data/trac/.local/lib64/
> ├── python2.7
> │ └── site-packages
> │ ├── PIL
> │ ├── Pillow-6.2.1.dist-info
> │ ├── PyPDF2
> │ ├── PyPDF2-1.26.0-py2.7.egg-info
> │ ├── reportlab
> │ ├── reportlab-3.5.32.dist-info
> │ ├── xhtml2pdf
> │ └── xhtml2pdf-0.2.3-py2.7.egg-info
> └── python3.6

Have you added the path to configuration of your web server?
Please share the configuration here if unable to solve it.

Mo

unread,
Nov 12, 2019, 5:46:28 AM11/12/19
to Trac Users
Am Freitag, 8. November 2019 11:09:32 UTC+1 schrieb Jun Omae:

Have you added the path to configuration of your web server?
Please share the configuration here if unable to solve it.

How do I make uwsgi find the local python libraries such as ~/.local/lib64/python2.7/site-packages ?
My uwsgi.ini looks like:

# cat /etc/uwsgi.d/trac-pp.ini

[uwsgi]
plugins
= python27
chown
-socket = trac:nginx
uid
= trac
gid
= trac
workers
= 6
socket
= /run/uwsgi/%n.sock

env
= TRAC_ENV=/mnt/data/trac/projects/trac-pp
env
= PYTHON_EGG_CACHE=/mnt/data/trac/.python-eggs
module = trac.web.main
callable
= dispatch_request

It starts that some more plugins need external python libraries, like SqlQueryMacro needs pymills and TracWikiPrintPlugin needs xhtml2pdf.

Beside that, the maintained alternative for SqlQueryMacro is SqlAlchemyQueryMacro which I also fail to install as the installation procedure is completely different:
https://trac-hacks.org/ticket/13644

And to complete the list of failures, the next alternative I tried is TracSQL and also failing with its installation procedure: https://github.com/trac-hacks/tracsql/issues/4

Any idea?
Best regards.

Mo

unread,
Nov 12, 2019, 7:04:28 AM11/12/19
to Trac Users
Am Dienstag, 12. November 2019 11:46:28 UTC+1 schrieb Mo:

How do I make uwsgi find the local python libraries such as ~/.local/lib64/python2.7/site-packages ?

I got it solved by adding this line to the uwsgi ini file:

pythonpath = /mnt/data/trac/.local/lib64/python2.7/site-packages


Reply all
Reply to author
Forward
0 new messages