A global plugin problem
Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Sent: Friday, January 14, 2022 8:27 PM To: nvda-addons@groups.io Subject: [nvda-addons] A global plugin problem
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Sent: Friday, January 14, 2022 7:14 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Sent: Friday, January 14, 2022 10:17 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
Ok I am stuck. Is there some way to install packages because so far nothing I do has made it so I can use the following packages in a plugin
Aenum, and pillow.
If I was writing a regular python program I would just pip install the packages and be done. Since this is enclosed in nvda this does not work. I don’t see anything in the development documents about this problem. Is it that no one uses external packages with their plugins? That is a big shocking.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry via groups.io
Sent: Friday, January 14, 2022 11:21 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Hi, Resource Monitor uses psutil module. To use external Python modules, you must copy the contents of the module to the place where you need to use it. For example, to use psutil inside a global plugin named “something”, you must copy the psutil module folder itself to globalPlugins/something and import it from __init__.py. This will work well if the module uses Python standard libraries that ships with NVDA (as part of its package process, Python will call py2exe to package NVDA modules and dependencies inside an executable archive powered by NSIS, as py2exe will pick up libraires that NVDA and its dependencies import). Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Sent: Saturday, January 15, 2022 10:32 AM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Ok I am stuck. Is there some way to install packages because so far nothing I do has made it so I can use the following packages in a plugin
Aenum, and pillow.
If I was writing a regular python program I would just pip install the packages and be done. Since this is enclosed in nvda this does not work. I don’t see anything in the development documents about this problem. Is it that no one uses external packages with their plugins? That is a big shocking.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry via groups.io
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
This worked in the old plugin now though with PIL it is telling me that image.py in pil can’t import
From . import image.py
So I do:
From PIL import ImageGrab
Then when I run the plugin Ig et an error saying File "C:\Users\kperr\AppData\Roaming\nvda\scratchpad\globalPlugins\graphiti\__init__.py", line 17, in <module> from PIL import ImageGrab File "C:\Users\kperr\AppData\Roaming\nvda\scratchpad\globalPlugins\graphiti\PIL\ImageGrab.py", line 20, in <module> from . import Image File "C:\Users\kperr\AppData\Roaming\nvda\scratchpad\globalPlugins\graphiti\PIL\Image.py", line 89, in <module> from . import _imaging as core ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\kperr\AppData\Roaming\nvda\scratchpad\globalPlugins\graphiti\PIL\__init__.py) INFO - core.main (14:52:30.502) - MainThread (18752):
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Sent: Saturday, January 15, 2022 2:30 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Hi, Resource Monitor uses psutil module. To use external Python modules, you must copy the contents of the module to the place where you need to use it. For example, to use psutil inside a global plugin named “something”, you must copy the psutil module folder itself to globalPlugins/something and import it from __init__.py. This will work well if the module uses Python standard libraries that ships with NVDA (as part of its package process, Python will call py2exe to package NVDA modules and dependencies inside an executable archive powered by NSIS, as py2exe will pick up libraires that NVDA and its dependencies import). Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Ok I am stuck. Is there some way to install packages because so far nothing I do has made it so I can use the following packages in a plugin
Aenum, and pillow.
If I was writing a regular python program I would just pip install the packages and be done. Since this is enclosed in nvda this does not work. I don’t see anything in the development documents about this problem. Is it that no one uses external packages with their plugins? That is a big shocking.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry via groups.io
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
I just read you remail again. I thought nvda was running in python 3. Are you saying it is still py 2.x? That could be my problem if it is. I will go look at the git repo I have of NVDA.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Sent: Saturday, January 15, 2022 2:30 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Hi, Resource Monitor uses psutil module. To use external Python modules, you must copy the contents of the module to the place where you need to use it. For example, to use psutil inside a global plugin named “something”, you must copy the psutil module folder itself to globalPlugins/something and import it from __init__.py. This will work well if the module uses Python standard libraries that ships with NVDA (as part of its package process, Python will call py2exe to package NVDA modules and dependencies inside an executable archive powered by NSIS, as py2exe will pick up libraires that NVDA and its dependencies import). Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Ok I am stuck. Is there some way to install packages because so far nothing I do has made it so I can use the following packages in a plugin
Aenum, and pillow.
If I was writing a regular python program I would just pip install the packages and be done. Since this is enclosed in nvda this does not work. I don’t see anything in the development documents about this problem. Is it that no one uses external packages with their plugins? That is a big shocking.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry via groups.io
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Ken Perry
Ok. I just changed my modules I am using to the 3.7 versions since that is what nvda is using. I moved them into my graphiti folder so that:
Scratchpad\globalplugins\graphiti\PIL Scratchpad\globalplugins\graphiti\aenum Scratchpad\globalplugins\graphiti\graphti.py
Are all in that location
I then do the following in my __init__.py
From . import graphiti
I didn’t have to do that last time but it seems to be working for that this time. Last time with NVDA I just did
Import graphiti
Here is the current problem in __init__.py, I do:
From PIL import ImageGrab
In the PIL module in ImageGrab.py there are imports like
From . import Image From . import _imaging as core
Those two lines are failing because it can’t find them all though they are there.
I have added PIL to the site-packages path to see if that would help but it did not.
I am starting to wonder if there is something wrong under scratchpad where things are not being added to the python path in nvda. Like I said this all used to work fine in the old NVDA before the scratchpad was added. I have the settings in nvda set and I know my plugin works because if I remove all the graphiti, PIL, and aenum code and just put messages in the place it works. I guess if someone out there is interested in helping me I could send them the code I have. Like I said this is not a top secret bit of code or anything.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Sent: Saturday, January 15, 2022 2:30 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem
Hi, Resource Monitor uses psutil module. To use external Python modules, you must copy the contents of the module to the place where you need to use it. For example, to use psutil inside a global plugin named “something”, you must copy the psutil module folder itself to globalPlugins/something and import it from __init__.py. This will work well if the module uses Python standard libraries that ships with NVDA (as part of its package process, Python will call py2exe to package NVDA modules and dependencies inside an executable archive powered by NSIS, as py2exe will pick up libraires that NVDA and its dependencies import). Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
Ok I am stuck. Is there some way to install packages because so far nothing I do has made it so I can use the following packages in a plugin
Aenum, and pillow.
If I was writing a regular python program I would just pip install the packages and be done. Since this is enclosed in nvda this does not work. I don’t see anything in the development documents about this problem. Is it that no one uses external packages with their plugins? That is a big shocking.
Ken
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry via groups.io
Ok that makes since. And it works partly. I also need to use the PIL library so when I did the old plugin I put the package for PIL and the package for aenum in the folder. And then referenced them just like I would any other time. Now that is not working. The following is the code I used before what do I need to do now. Is there a better way to include two packages that are not installed with NVDA.
PLUGIN_DIR = os.path.dirname(__file__)
# Add bundled copy of PIL to module search path. sys.path.append(os.path.join(PLUGIN_DIR, "PIL")) import ImageGrab del sys.path[-1]
I have another set of this code in graphit.py to import from aenum but it used to be From aenum import IntFlag From aenum import enum
Now that will not work. I tried doing all kinds of things for the above problem but I am at a loss how to fix it. Is there a way to install packages into plugins now or is there some python way to fix this.
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Joseph Lee
Hi, You must use relative import like so: from . import modname
This, by the way, also works in Python 2. Cheers, Joseph
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I don’t mind saying exactly what it is. I do wish there was a generic answer. This is to fix the Graphiti plugin. It is for a demo unit. My file structure right now looks something like this
Scratchpad/ globalPlugins/Graphiti/__init__.py Scratchpad/ globalPlugins/graphiti/graphiti.py
The code in __init__.py looks like: Import graphiti
The graphiti class is the driver for the device. I use it in other programs with no problem just like this and it worked when I used it in the global plugin for the older version of NV DA. I have updated the Graphiti.py and the __init__.py and the __init__.py works if I replace the use of the graphiti.py with messages to test it. The error in the log is on the line where the import graphiti is and the log says it can’t find the graphiti module.
Ken From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Travis Roth
I think this changed in python3 and I usually have to mess around until it works. I don’t know the directory structure you have, but for something like \addon\appModules\appllicationName
If you then have __init__.py and myModule.py and myFunctions.py you need to tell it to look in the current directory for other files in that folder such as import .myModule from .myFunctions import makeBraille, makeSpeech
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Ken Perry
I have an old global plug in for before NVDA was switched to 3.x It worked fine and I have fixed all the problems that have to do with the difference in python types.
Here is the problem I have several python files in the global plugin. The
__init__.py file has an import like this:
Import myclass
Then there is a file in the same folder
Myclass.py
The global plugin can not find the file I am importing. It used to work fine is there some new thing I have to do to let the global plugin know where my other classes are? Note I have my global plugin in a folder like myplugin under the developer scratchpad folder and I know it is at least being found because if I take the class I am importing out the key press works fine and presents the message I want it to. In the log though it says it can’t find myclass module.
Ken
|
|
Alberto Buffolino
Ken Perry, il 15/01/2022 21.49, ha scritto:
Ok. I just changed my modules I am using to the 3.7 versions since that is what nvda is using. I moved them into my graphiti folder so that:Alberto: 3.7 32-bit? However, scratchpad is for simple modules, if you're starting to import libraries I suggest to create an add-on, and consider to put PIL and other folders under a lib directory, in same (not under) path of globalPlugin folder. About PIL/Pillow, what procedure you have follow to collect its files? Alberto
|
|
Ken Perry
Not sure if it is 32 bit or 64. I will check that but I don't think that matters being that the scripts are loading.
toggle quoted messageShow quoted text
Scratchpad is not for simple modules it is for developing modules of any kind as far as I know. As for your question, " About PIL/Pillow, what procedure you have follow to collect its files?" I don't understand what your asking here.
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Alberto Buffolino Sent: Sunday, January 16, 2022 1:09 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem Ken Perry, il 15/01/2022 21.49, ha scritto: Ok. I just changed my modules I am using to the 3.7 versions sinceAlberto: 3.7 32-bit? However, scratchpad is for simple modules, if you're starting to import libraries I suggest to create an add-on, and consider to put PIL and other folders under a lib directory, in same (not under) path of globalPlugin folder. About PIL/Pillow, what procedure you have follow to collect its files? Alberto
|
|
Alberto Buffolino
Ken Perry, il 16/01/2022 19.34, ha scritto:
Scratchpad is not for simple modules it is for developing modules of any kind as far as I know.Alberto: I'm not sure, I remember errors on absence of GlobalPlugin class, like if NVDA would want to find only NVDA modules, and to redistribute you should change folder structure and code accordingly, so... but ok, this is a my personal opinion. " About PIL/Pillow, what procedure you have follow to collect its files?"Alberto: I'm asking what actions you have done to populate PIL folder, or where you copied it from. Have you installed it via pip and then copied some files? Or have you downloaded Pillow-9.0.0-cp37-cp37m-win32.whl from Pypi and then extracted the PIL folder? I suspect the latter is a good procedure, but I not tested yet. Alberto
|
|
Ken Perry
Ah Ok to be clear about the whole process.
toggle quoted messageShow quoted text
I have created a Graphiti folder which will be a global plugin. This plugin worked in the past. It is currently under scratchpad global plugins. I used pip in my windows python3.7.2 since that is what I saw NVDA was using to pip install pillow and aenum. My test program to do what I want the plugin to do works fine outside of NVDA. I Then copied pil, a pil folder from site-packages, pillow dist file and aenum from the site-packages folder and an aenum file into the graphiti folder. I also have one Graphiti.py in the graphiti folder that is the code that controls the graphiti. Finally I have the script for NVDA __init__.py All of that is in the graphiti folder. I copied it using the windows GUI copy so it should have copied the entire folder. I do wish that NVDA had a pip of its own or some system that add-ons or plugins could add libraries without copying. This all worked in the older nvda. Again I test by commenting out the librarys and the plugin is definitely being activated because I can see my messages. I am more than willing to zip this up if experts out there think they can see the problem. Ken
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Alberto Buffolino Sent: Sunday, January 16, 2022 1:54 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem Ken Perry, il 16/01/2022 19.34, ha scritto: Scratchpad is not for simple modules it is for developing modules of anykind as far as I know. Alberto: I'm not sure, I remember errors on absence of GlobalPlugin class, like if NVDA would want to find only NVDA modules, and to redistribute you should change folder structure and code accordingly, so... but ok, this is a my personal opinion. " About PIL/Pillow, what procedure you have follow to collect its files?"Alberto: I'm asking what actions you have done to populate PIL folder, or where you copied it from. Have you installed it via pip and then copied some files? Or have you downloaded Pillow-9.0.0-cp37-cp37m-win32.whl from Pypi and then extracted the PIL folder? I suspect the latter is a good procedure, but I not tested yet. Alberto
|
|
Lukasz Golonka
I've bundled pillow with my OCR add-on for Python 3 based NVDA
successfully in the past, so this is certainly possible. My folder layout was as you've described i.e: - A folder in the golbalPlugins folder of my add-on - Inside it a __init__.py and an PIL folder. In __init__.py I had the following code: PLUGIN_DIR = os.path.dirname(__file__) # Pillow requires pathlib which is not bundled with NVDA # Therefore place it in the plugin directory and add it temporarily to PYTHONPATH sys.path.append(PLUGIN_DIR) from .PIL import ImageGrab from .PIL import Image del sys.path[-1] If you want feel free to send a zip file of the plugin and I can take a look. -- HTH Lukasz On Sun, 16 Jan 2022 16:02:21 -0500 "Ken Perry" <kperry@blinksoft.com> wrote: Ah Ok to be clear about the whole process.
|
|
Ken Perry
I will try that. That is almost exactly the same as my plugin was when I started. I did copy some of the early plugin for tesseract when I originally wrote this over 3 years ago. If it doesn't work again I will definitely zip it up and put it up on my drop box for you to get it.
toggle quoted messageShow quoted text
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Lukasz Golonka via groups.io Sent: Sunday, January 16, 2022 4:20 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem I've bundled pillow with my OCR add-on for Python 3 based NVDA successfully in the past, so this is certainly possible. My folder layout was as you've described i.e: - A folder in the golbalPlugins folder of my add-on - Inside it a __init__.py and an PIL folder. In __init__.py I had the following code: PLUGIN_DIR = os.path.dirname(__file__) # Pillow requires pathlib which is not bundled with NVDA # Therefore place it in the plugin directory and add it temporarily to PYTHONPATH sys.path.append(PLUGIN_DIR) from .PIL import ImageGrab from .PIL import Image del sys.path[-1] If you want feel free to send a zip file of the plugin and I can take a look. -- HTH Lukasz On Sun, 16 Jan 2022 16:02:21 -0500 "Ken Perry" <kperry@blinksoft.com> wrote: Ah Ok to be clear about the whole process.
|
|
Ken Perry
Here is a link to the broken Graphiti plugin. I think you will see I have what you say in the code. It does not work.
toggle quoted messageShow quoted text
The link to the graphiti plugin https://www.dropbox.com/s/ckj23wr2xsop7ov/graphiti.zip?dl=0
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Lukasz Golonka via groups.io Sent: Sunday, January 16, 2022 4:20 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem I've bundled pillow with my OCR add-on for Python 3 based NVDA successfully in the past, so this is certainly possible. My folder layout was as you've described i.e: - A folder in the golbalPlugins folder of my add-on - Inside it a __init__.py and an PIL folder. In __init__.py I had the following code: PLUGIN_DIR = os.path.dirname(__file__) # Pillow requires pathlib which is not bundled with NVDA # Therefore place it in the plugin directory and add it temporarily to PYTHONPATH sys.path.append(PLUGIN_DIR) from .PIL import ImageGrab from .PIL import Image del sys.path[-1] If you want feel free to send a zip file of the plugin and I can take a look. -- HTH Lukasz On Sun, 16 Jan 2022 16:02:21 -0500 "Ken Perry" <kperry@blinksoft.com> wrote: Ah Ok to be clear about the whole process.
|
|
Lukasz Golonka
This cannot work since you're bundling a 64-bit version of PIL and NVDA
is running on 32-vit Pythion. Please install a 32-bit version of Python 3.7, install PIL there, copy its files into your plugin and retry. On Sun, 16 Jan 2022 17:22:36 -0500 "Ken Perry" <kperry@blinksoft.com> wrote:
-- Regards Lukasz
|
|
Ken Perry
Ok will try that.
toggle quoted messageShow quoted text
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Lukasz Golonka via groups.io Sent: Sunday, January 16, 2022 5:32 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem This cannot work since you're bundling a 64-bit version of PIL and NVDA is running on 32-vit Pythion. Please install a 32-bit version of Python 3.7, install PIL there, copy its files into your plugin and retry. On Sun, 16 Jan 2022 17:22:36 -0500 "Ken Perry" <kperry@blinksoft.com> wrote:
-- Regards Lukasz
|
|
Ken Perry
Ok. Thanks. That actually fixed the import. I had to change the Graphiti import to
toggle quoted messageShow quoted text
From . import graphiti And fix a couple typo's in the Graphiti file but now it is working perfectly. I probably need to do some threading so it doesn't slow down nVDA when it starts. I also need to make a method to find a graphiti if it is plugged in rather than having the comm port set. With that said I love been able to see the screen instantly. I can't believe that the problem was just the win32 thing. I keep forgetting that python has built in libraries that don't rebuild when python runs. Thanks for the help. Ken
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Lukasz Golonka via groups.io Sent: Sunday, January 16, 2022 5:32 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] A global plugin problem This cannot work since you're bundling a 64-bit version of PIL and NVDA is running on 32-vit Pythion. Please install a 32-bit version of Python 3.7, install PIL there, copy its files into your plugin and retry. On Sun, 16 Jan 2022 17:22:36 -0500 "Ken Perry" <kperry@blinksoft.com> wrote:
-- Regards Lukasz
|
|