Page 1 of 1

Adding site-packages installed via pip automatically to SP

Posted: Mon Jan 29, 2018 4:15 pm
by Pudge90
I installed a site-package via pip. Let's cal it "mypackage"
If I have modules in my SP-plugin that use mypackage then, SP tells me when loading the plugin 'ModuleNotFoundError: No module named 'mypackage' .
If in python, entering this:

Syntax: Select all

import sys
for line in sys.path: print(line)

it says that
/home/user1/.local/lib/python3.5/site-packages
is there. So python kinda knows where to look for my site-packages. Yet i don't know how to tell SP to look for packages in /home/user1/.local/lib/python3.5/site-packages

Copying mypackage to /addons/source-python/packages/site-packages/ gives my another bunch of errors (that are probably on my side only). But is there any other way? Like automatically adding packages installed via pip to SP ? Or is SP designed to NOT include packages installed via pip ?

Re: Adding site-packages installed via pip automatically to SP

Posted: Mon Jan 29, 2018 6:46 pm
by Ayuto
Using pip of a different Python installation doesn't install the package to SP unless you instruct pip to do so by defining the installation location. I can't remember the options you need to pass and I'm currently on the phone, so you need to look up the options on your own or wait a little bit.

Moreover, you need to use pip from a Python 3.6 installation, because SP embeds 3.6. You are currently using 3.5. This might work if the package doesn't contain anything that needs to be compiled, but if it does, it's mandatory to use the same versions.

Out of curiosity: what package do you want to install?

Re: Adding site-packages installed via pip automatically to SP

Posted: Mon Jan 29, 2018 9:47 pm
by Pudge90
My package works now so I guess nothing needs to be compiled again. I went with the copying for the testing.
The pip-install-directory-thing would be I guess:

Syntax: Select all

pip install <package> -t <directory>

Thank you :grin:
Instead of setting the installation-directory in pip, could I also tell SP to look for site-packages in a specific location ? So that SP additionally searches for packages in the pip default installation-directory.
I am trying to install OpenPyXL for lazy-reasons :grin: sql would be a trillion times faster but I can open an xlsx-file almost everywhere with close to zero effort and for my purpose I don't necessarily need sql.

Re: Adding site-packages installed via pip automatically to SP

Posted: Mon Jan 29, 2018 11:15 pm
by satoon101
Pudge90 wrote:Instead of setting the installation-directory in pip, could I also tell SP to look for site-packages in a specific location ?

I personally don't think that is a good idea.

At some point, we should include pip in our releases. If I remember correctly, when I tried to do that a couple years ago, it worked fine on Windows (at least for packages that required no extra compiling), but I had some issues on Linux.

Pudge90 wrote:I am trying to install OpenPyXL for lazy-reasons :grin: sql would be a trillion times faster but I can open an xlsx-file almost everywhere with close to zero effort and for my purpose I don't necessarily need sql.

I'm not entirely sure what you are attempting to do, but it sounds to me that perhaps a csv would be a better idea than an xlsx. Though, sql is also a good idea, normally, and much better to work with than xlsx files (in my opinion). Again, though, I'm not sure what the full context of your situation is.

Re: Adding site-packages installed via pip automatically to SP

Posted: Tue Jan 30, 2018 11:53 am
by Pudge90
satoon101 wrote:I personally don't think that is a good idea.

Okay then I just go with telling pip to install to the SP directory, thanks.

satoon101 wrote: Again, though, I'm not sure what the full context of your situation is.

Well right now I am just playing around with SP to see what I could do with it. As a 'small' project I am trying to recreate the original WCS mod but from scratch. It's ugly and inefficient but I get to learn a lot throughout the process of creating it and thats what I am doing it for.
The xlsx is just what I use to store EXP and stuff like that. So at some point I will switch to sql. CSV indeed could be worth a try.

Re: Adding site-packages installed via pip automatically to SP

Posted: Wed Jan 31, 2018 10:18 am
by Doldol
It's kind of offtopic, but have you tried JSON instead of xlsx/csv? Python has build in read/write support and JSON structures very closely represent Python datatypes.

Re: Adding site-packages installed via pip automatically to SP

Posted: Wed Jan 31, 2018 3:21 pm
by Pudge90
Doldol wrote:It's kind of offtopic, but have you tried JSON instead of xlsx/csv? Python has build in read/write support and JSON structures very closely represent Python datatypes.

I have never worked with JSON before but I had a quick look at it. If I have the time to read myself into JSON it might be a good alternative for my purpose. Thanks!

Re: Adding site-packages installed via pip automatically to SP

Posted: Wed Jan 31, 2018 4:45 pm
by satoon101
I second this idea in your situation. JSON is very easy to work with and is extremely human readable.