Best way to install packages into EG's Python? Can't run pip

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
jwilcox25
Posts: 14
Joined: Thu Jan 22, 2009 4:19 am

Best way to install packages into EG's Python? Can't run pip

Post by jwilcox25 » Wed Sep 20, 2017 7:44 pm

I'm trying to install new python packages directly for EG's interpreter after having some trouble with importing modules requiring C extensions from a different Python installation using PYTHONPATH. What is the best way to do this? I tried installing pip by "C:\Program Files (x86)\EventGhost\py.exe" get-pip.py but I cannot run it after install

Running "C:\Program Files (x86)\EventGhost\lib27\Scripts\pip.exe", I get

Traceback (most recent call last):
File "py.py", line 29, in <module>
File "C:\Program Files (x86)\EventGhost\lib27\Scripts\pip.exe", line 1
SyntaxError: Non-ASCII character '\x90' in file C:\Program Files (x86)\EventGhost\lib27\Scripts\pip.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

It seems as if it's thinking that I am running py.exe pip.exe, but I am not - I'm just running pip.exe

Alternatively, trying to import pip in Stackless, I get:

Python 2.7.12 Stackless 3.1b3 060516 (default, Oct 31 2016, 18:42:08) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pip
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "pip\__init__.pyc", line 26, in <module>
File "pip\utils\__init__.pyc", line 22, in <module>
File "pip\compat\__init__.pyc", line 26, in <module>
ImportError: No module named ipaddr
>>> import ipaddr
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named ipaddr

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run

Post by kgschlosser » Thu Sep 21, 2017 6:25 am

you have to install python 2.7 then install the package into that. if you run eg 0.5 it will automatically locate the python 2.7 installation and include the site_packages from that installation into the path for the interpreter that EG runs.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run

Post by kgschlosser » Thu Sep 21, 2017 6:31 am

also.. some packages will not work properly because of DLL's and being compiled, things of that nature. I can build you a version of EG that will allow you to run pip or easy_install from inside of a python script. This is will not support at all because even with this being done there will still be some libraries that will not install properly. as an example pyQT. in that case it would have to be added during the build process. Trying to support that many "flavors" of EG would be way to difficult.
If you like the work I have been doing then feel free to Image

jwilcox25
Posts: 14
Joined: Thu Jan 22, 2009 4:19 am

Re: Best way to install packages into EG's Python? Can't run

Post by jwilcox25 » Thu Sep 21, 2017 11:38 am

kgschlosser wrote:also.. some packages will not work properly because of DLL's and being compiled, things of that nature. I can build you a version of EG that will allow you to run pip or easy_install from inside of a python script. This is will not support at all because even with this being done there will still be some libraries that will not install properly. as an example pyQT. in that case it would have to be added during the build process. Trying to support that many "flavors" of EG would be way to difficult.
Got it. Yes having pip / easy_install available would be great. Or, is there a folder I can move DLL/PYD files so that the EG interpreter will pick them up?

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run pip

Post by kgschlosser » Sun Sep 24, 2017 1:14 am

it all depends on the package you have installed. but you can either move them to


for eg 0.4 - \program files (x86)\eventghost\py26\site_packages
for eg 0.5 - \program files (x86)\eventghost\py27\site_packages

tho if you run eg 0.5 you don't need to worry about moving them if you installed the packages into a python 2.7 installation. EG automatically seeks out any python installations
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 612
Joined: Sat Feb 13, 2016 8:39 pm

Re: Best way to install packages into EG's Python? Can't run pip

Post by jachin99 » Tue Oct 03, 2017 6:51 pm

What about the option to add packages that might be needed for EG plugins? That way the responsibility to maintain things falls on the plugin dev, and it frees up others from being burdened with supporting all kinds of weird branches. My specific use case is for an RSS reader. I could be doing something wrong but I can't import feedparser to return values from an RSS feed in EG.

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run pip

Post by kgschlosser » Tue Oct 03, 2017 9:25 pm

what is the name of the library you are trying to use.

and some libraries cannot be "transferred" to EG unfortunately they have to be added at build time. for instance pyQT. I did add the ability to install packages into EG at one point it worked pretty well. the problem is there are still packages that need additional things. like C compilers or programs that are external to EG. I would love to add the ability. if it was 100% working. meaning PIP or easy_install they don't work 100% of the time if you use them from a python installation. The other thing is that python does ship with EG but it has been modified in a way that makes it so that any package installer is unable to modify or add any files to it. I would have to think of some crazy monkey patch to allow this. It ends up turning into a support nightmare because things that are not really an EG problem become one.

EG is really really easy to build now so anyone can build their own version of it. and actually you don't even have to build it. if you fork the repo on github and add the github "plugin" called appveyor when you modify it adding what you want. when you commit the changes appveyor will then do the build for you and it will spit out an installer for ya.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 612
Joined: Sat Feb 13, 2016 8:39 pm

Re: Best way to install packages into EG's Python? Can't run pip

Post by jachin99 » Wed Oct 04, 2017 1:09 pm

kgschlosser wrote:
Sun Sep 24, 2017 1:14 am
tho if you run eg 0.5 you don't need to worry about moving them if you installed the packages into a python 2.7 installation. EG automatically seeks out any python installations
The package I am looking at is feedparser. I don't have python installed on any of the machines I have around the house but lets say i did want to run a python script from EG that required a package not included with the regular python 27 distro. i understand that I can download the package and put it into its appropriate folder but will EG see and use that package's capabilities, or is there some extra step required where I have to point EG to the package?

As a general rule, if it can be installed using PIP or Easy_Install, then it can be easily added to EG correct? I wasn't really talking about doing things like bolting on anything too complicated, just small packages like feedparser. I hope my questions are pretty clear, and if I went sideways anywhere or dont make any sense, let me know. I'm still pretty clueless about this stuff.

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run pip

Post by kgschlosser » Wed Oct 04, 2017 2:58 pm

no you're good..


when installing a package via pip or easy_install into a python installation there are some packages that will modify or add files to the core python files. this is basically anything located outside of the site-packages and scripts folder. if the package you are installing does this then it cannot be added to EG and EG will not necessarily run it properly. Unless you add the directory of said added files to your system PATH statement. but even then it is no guarantee. This is a small number of packages that do this kind of a thing. but they are out there. Most packages can be installed into a python installation and then copied to the lib27 (orlib26 for EG 0.4)/site-packages folder without issue (if you wanted to remove the python installation or install the packages onto a machine without python installed)


So this is the pecking order of things.

when you start EG several things happen. the first thing that happens is when the python interpreter starts (the back end of EG) it will add the location of the standard python packages to it's internal PATH statement (sys.path) it adds the EventGhost modules path (the eg folder) as well. Then it goes poking about in your registry looking for any python installations. and if python is installed it will add the path to the python installations folder as a site. I do not remember off hand where it places that directory into sys.path i believe it tacks it onto the end. the order in which these are added is important because that is also the order in which it will search for an installed package when you use the import statement. so if you have an old version of a package installed into lib27/site-packages and a new one installed in a python installation when running import package i believe it will load the old one.

package/module path search order

c:\program files (x86)\eventghost\lib27\py27.zip
c:\program files(x86)\eventghost\lib27\
c:\program files(x86)\eventghost\eg\
c:\program files(x86)\eventghost\lib27\site-packages\
c:\python\libs\site-packages\ (if python is installed and this is where it is installed)
current working directory


if making a plugin and you want to include a specific package to your plugin. you can either give instruction to the user on how to obtain the package and install it. or in most scenarios you can simply copy and paste the package into the plugins folder. NOTE: if placing the package into the plugins folder be sure to do your imports as follows "from . import package: or from .package import module this will make sure that the plugin is loading the module you included with your package and not one that may be from a python installation or one that has been added to the EG site-packages folder.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5146
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Best way to install packages into EG's Python? Can't run pip

Post by kgschlosser » Wed Oct 04, 2017 3:03 pm

and as far as any extra steps needed. that all depends on the package being installed. some are not a simple download and copy. some of them will need to be compiled by pip or easy_install and this gets done at install time. so it is always best to have a python installation do the work and then you copy it from that python install into your lib17 (lib26 for 0.4)\site-packages folder. if there is some other additional file that is created and possibly added to the python lib folder you can also include this but you will need to change the statements in the package that point to it and change them to the new location in which you decided to move it to.
If you like the work I have been doing then feel free to Image

Post Reply