No module named 'data' - python-import

I get the error No module named 'data' whenever I try to execute the line below
from data import batch_gen, encode
Can anyone help me fix this? I tried looking into other online resources but could not fix this problem.

try the following and then do your import:
pip install data

The line
from data import batch_gen, encode
lets you import only parts of modules and gives you the possibility to reference them directly without writing data.encode
So to get this running you need a module called data in a file, either a file in the same location as your python file or in the installation folder where the other std python files life. otherwise you would always get an error. more information is easily found here:
https://www.digitalocean.com/community/tutorials/how-to-import-modules-in-python-3#using-from-%E2%80%A6-import

Related

Importing python packages within python packages (relative imports, __init__.py)

Let's say I have a directory like this
In main.py I have the code from main_package import func but I get an error saying
test/main_package/func.py", line 1, in <module>
from sub_package.aa import aaf1
ModuleNotFoundError: No module named 'sub_package'
The line from sub_pacakage.aa import aaf1 in main_package/func.py is causing the error. I can switch that line to an asbolute path (from main_package.sub_pacakage.aa import aaf1) and it works fine.
However, I want to not change the relative path to an absolute path.
I am assuming I have to modify main_package/__init__.py to achieve this but I am not sure how. How do I go about this?
I've tried adding from . import sub_package to main_package/__init__.py but it doesn't seem to be working.
The issue with absolute Python imports is that they are actually relative to any path defined in sys.path and also to your current working directory.
Thus, to make an import like from sub_package.aa work, you need to ensure that the parent folder of "sub_package" is in sys.path or is your current working directory.
The same goes for from main_package.sub_package.aa. You need to make sure that the parent folder of main_package is in sys.path or is your current working directory. So it makes a different how and from which directory you execute your Python code. You usually need to "cd" to the right directory first.
I've had similar problems in the past and thus I've created an experimental, new import library: ultraimport
It gives you more control over your import and lets you do file system based imports and therefore real relative imports. You could then write your func.py like this:
import ultraimport
# Given that aaf1 is defined in aa.py from your sub package
aaf1 = ultraimport('__dir__/subpackage/aa.py', 'aaf1')
This will always work, no matter what is your current working directory, what is your sys.path or how you run your code.

Agda Installation PLFA Configuration

I am trying to use the Programming Language Foundation with Agda plfa library, however the import does not appear to be working properly.
I have cloned the repository and added the repository path to: ~/.agda/libraries and plfa to ~/.agda/defaults.
When I create a test.agda file and check a single line
module plfa.part1.Naturals where
I get an import error:
You tried to load /Users/johngfisher/Desktop/agda_test/nats.agda
which defines the module plfa.part1.Naturals. However, according to
the include path this module should be defined in
/Users/johngfisher/agda_env/libraries/plfa/src/plfa/part1/Naturals.lagda.md
The file is present in the location the import is coming from so I am unsure of why Agda is unable to find it. Any help would be appreciated.
module plfa.part1.Naturals where
defines a module named plfa.part1.Naturals
Did you mean to type
module test where
open import plfa.part1.Naturals
instead?

How to refer to files that were added via the data_files attribute?

With py2app, say I added several files to my package using this:
DATA_FILES = [
('images', ['images/picture.jpg', 'images/picture2.png']),
('images/icons', ['images/icons/ico1.ico'])
]
and in my original I used to access these files using './images/picture.jpg' for example. How should I refer to them now?
I've tried both using the same path and using ./Contents/Resources//images/picture.jpg but neither work
In general, paths obtained via os.getcwd() refer to ./Contents/Resources/ after running py2app on my machine.
To better understand your exact problem, run the executable file in *.app/Contents/MacOS/, then copy and share the traceback error message that comes up in your Terminal console. Also, try to insert print statements to analyse your paths in Terminal.

I see an angular2 'bind' function defined in angular2/angular2.d.ts - did it used to be in 'angular2/di.d.ts?

Many of the samples I have seen for angular2 have the following import statement:
import {bind} from 'angular2/di';
I am working in VS Code (with TypeScript) and it complains about not being able to find the angular2/di module.
However I do see a bind function defined in angular2/angular2.d.ts. If I change the import statement to the following, then the error goes away.
import {bind} from 'angular2/angular2';
Is the question in the title off-base and I am making some erroneous assumption?
If not, why do many samples reference one module to import the bind function from, yet I seem to be able to get it from a different module?
Most likely because you looked at versions from older alphas. Look at the angular2.ts file. Everything is exported from it. Also note that the d.ts is going to contain everything to resolve types in your IDE and at compilation time. What import does is actually importing the .js files.

is there a good way to find function define in header file in ace framework

As a ace framework newer, i always encounter some problem when using this framework.
I copy some example code from website and execute it in linux. however some error throw out because of no include correspond header file. for exmaple some error like this: error: ‘sleep’ is not a member of ‘ACE_OS’.
so how can i found this function define in which header file
Most easiest is just to do a "grep sleep $ACE_ROOT/ace/OS*.h", that tells you the file where this method is defined. Other option is to use the most recent doxygen tree at http://doxygen.theaceorb.nl/libace-doc/index.html

Resources