Python module doesn't find file include in MANIFEST.in - python-3.x

So I have made a small gui application using pygobject.
Works fine and all when executed from the directory.
Tried to make a python package out of it but get this error everytime:
In [2]: pygofortune.pygofortune.main()
---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-2-1e2e05b4c484> in <module>()
----> 1 pygofortune.pygofortune.main()
/usr/lib/python3.5/site-packages/pygofortune-0.1-py3.5.egg/pygofortune/pygofortune.py in main()
55 def main():
56 builder = Gtk.Builder()
---> 57 builder.add_from_file("fortune.glade")
58 builder.connect_signals(Handler())
59 global win, buffer, about
Error: g-file-error-quark: Failed to open file 'fortune.glade': No such file or directory (4)
I had include the files in MANIFEST.in.
The files were present in the sitepackages folder of package too.
Any ideas what I may have done wrong

A filename without a path component will be looked for relative to the current working directory, not the directory where the Python script is installed.
I suggest using something like the pkg_resources feature of Setuptools to install your data files to a known location and retrieve their paths at runtime.

Related

How to set path to Python executable in JupyterLab somewhere outside Anaconda

I need to be able to run JupyterLab on the Python executable in SPSS in order to import some SPSS libraries (spss, spssaux, SpssClient, etc.) in a notebook in JuptyerLab. Based on answers to other Ancadonda/executable-related questions, I've attempted two possible solutions:
Paste the relevant libraries from the Python directory in SPSS to the Python directory in Anaconda. I tried this both to the base environment and to the virtual environment I work out of, and tried launching JupyterLab both from the base and from the virtual environment. I copied the files from C:\Program Files\IBM\SPSS\Statistics\27\Python3\Lib\site-packages to C:\ProgramData\Anaconda3\Lib.
Redirect Anaconda to the Python executable in SPSS. I tried to to do that with sys.path.insert:
import sys
sys.path.insert(0, 'C:\Program Files\IBM\SPSS\Statistics\27\Python3')
Attempt #1 results in the following error when I try to import spss:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11344/2864419669.py in <module>
----> 1 import spss
C:\Program Files\IBM\SPSS\Statistics\27\Python3\Lib\site-packages\spss\__init__.py in <module>
254 __SetErrorMessage()
255
--> 256 from .spss import *
257 from .cursors import *
258 from .pivotTable import *
C:\Program Files\IBM\SPSS\Statistics\27\Python3\Lib\site-packages\spss\spss.py in <module>
21
22 import atexit,os,locale,sys,codecs
---> 23 from . import PyInvokeSpss
24 from .errMsg import *
25
ImportError: DLL load failed while importing PyInvokeSpss: The specified module could not be found.
This in spite of having copied PyInvokeSpss to C:\ProgramData\Anaconda3\Lib.
#2 doesn't seem to change the path to the executable:
C:\ProgramData\Anaconda3\python.exe
I also have an idea for a third solution, which would be to package the Python that's in SPSS as an iPython kernel, and then activate that in JupyterLab after it's launched, but I can't figure out a way of doing that.
What's the best direction here for a solution? What am I doing wrong?

ModuleNotFoundError: No module named 'genpy.rostime'. Trying to load a pickle file

I am trying to load a file which is a pickle compatible lists of dictionaries. My code is below:
with open('data/task_2/b.obj', 'rb') as file:
f = pickle.load(file)
The error I am getting is:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-133-5fce33f1537b> in <module>
1 with open('data/task_2/b.obj', 'rb') as file:
----> 2 f = pickle.load(file)
ModuleNotFoundError: No module named 'genpy.rostime'
I am using windows 10. Python 3.8 and anaconda. First time I tried this piece of code only genpy was missing and installed that using pip. Now I am stuck with this.
Any hints, suggestions are appreciated.
solution_1:
install genpy
solution_2:
You should find that where is 'genpy.rostime'.
Then add its root path to your python script.
If the "genpy" is in your current script directory, then the following will solve this problem.
sys.path.append(os.path.join(os.path.dirname(__file__), "."))

Import script in sub directory not working... Blender Add-On

I have a folder structure like this:
C:
|_Blueprint
│ main.py
│
└───toolbox
blueprint_tools.py
When I run this code in Blender's scripting text page:
from toolbox.blueprint_tools import dimension, array, modify
I get an error in the console
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ModuleNotFoundError: No module named 'toolbox'
Error: Python script failed, check the message in the system console
I swear, when I run this code (on other projects) outside of Blender this structure and code runs fine. But I get an error when running this script in Blender for testing out my Add-On.
If I compile the Blueprint folder into a .zip and install it everything works fine.... ??
I'm lost, could anyone please help me.
If I run the code like this: (added a . before toolbox for CWD)
from .toolbox.blueprint_tools import dimension, array, modify
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ImportError: attempted relative import with no known parent package
Error: Python script failed, check the message in the system console
Both your error traces write File \main.py ... which means that Blender considers your main.py file to be in the root folder, knowing nothing about its real location in the file system hierarchy.
When you installed your structure as a zip file, you provided all necessary info to Blender.
Addendum:
Temporarily, during developing / debugging your add-on, you may add the full path (for finding your toolbox.blueprint_tools module) to the sys.path variable.
There are 2 possibilities how to do it:
Insert into your main.py file these commands (use the path to your parent folder of your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox"]
before your statement
from toolbox.blueprint_tools import dimension, array, modify
command, or
Insert into your main.py file these commands (use the path to your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox\toolbox"]
before your modified statement
from blueprint_tools import dimension, array, modify

Error with import script in colaboratory

When I try to import a script that is in the same folder as the colaboratory
then I get an error:
ImportErrorTraceback (most recent call last)
<ipython-input-8-e7a4315427c8> in <module>()
----> 1 import translate
ImportError: No module named translate
The path and location of the file checked!!!
Colab doesn't automatically load any files from your Google Drive folder; you'll need to copy the files locally (eg with something like https://colab.research.google.com/notebooks/io.ipynb#scrollTo=P3KX0Sm0E2sF and then saving to a file).

How to setup SublimeREPL to load current working directory

I have installed ipython jupyter console for sublimeREPL using the link https://gist.github.com/MattDMo/6cb1dfbe8a124e1ca5af
However, I face a problem, when I start the "Jupyter Console", it doesn't load the current directory in which I am working.
For Instance, I am working on a file "text.py in directory "/home/sam/desktop/programs/" and I run a manual import "import text" in the sublimeREPL (jupyter console), I get a module not found error
ImportError Traceback (most recent call last)
<ipython-input-3-0660e90ee9d4> in <module>()
----> 1 import text
ImportError: No module named text
I refered to the link Set working directory to location of active script in SublimeREPL
and checked the directory of cwd using os.getcwd()
The directory that I see is /opt/sublimetext
I even tried changing the "cwd" from "cwd": "$file_path", to the current path,"cwd": "/home/sam/desktop/programs/" in the "Main.sublime-menu" file
I was wondering if there is a way that I could register the directory manually or even better if sublimeREPL would automatically pick the directory, since I'll be importing files from different locations.
Thanks.

Resources