Adding site-packages installed via pip automatically to SP

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Pudge90
Member
Posts: 33
Joined: Sun Jan 14, 2018 6:18 pm
Location: Germany

Adding site-packages installed via pip automatically to SP

Postby Pudge90 » Mon Jan 29, 2018 4:15 pm

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 ?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

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

Postby Ayuto » Mon Jan 29, 2018 6:46 pm

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?
User avatar
Pudge90
Member
Posts: 33
Joined: Sun Jan 14, 2018 6:18 pm
Location: Germany

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

Postby Pudge90 » Mon Jan 29, 2018 9:47 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

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

Postby satoon101 » Mon Jan 29, 2018 11:15 pm

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.
Image
User avatar
Pudge90
Member
Posts: 33
Joined: Sun Jan 14, 2018 6:18 pm
Location: Germany

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

Postby Pudge90 » Tue Jan 30, 2018 11:53 am

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.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

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

Postby Doldol » Wed Jan 31, 2018 10:18 am

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.
User avatar
Pudge90
Member
Posts: 33
Joined: Sun Jan 14, 2018 6:18 pm
Location: Germany

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

Postby Pudge90 » Wed Jan 31, 2018 3:21 pm

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!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

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

Postby satoon101 » Wed Jan 31, 2018 4:45 pm

I second this idea in your situation. JSON is very easy to work with and is extremely human readable.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 42 guests