Every time I try to load my file i get the error "Module "Main" already loaded".
The file i am trying to load loads another module, the module loads by itself fine.
The file only loads that module and nothing else.
Can anyone tell me why it is giving me this error?
Thanks
This is a Hugs error, and honestly my first recommendation would be to switch to GHC. Is there a particular reason you're using Hugs?
However, if you don't want to or can't switch, this page says the following:
This error happens if you load two anonymous modules into (Win)Hugs. The solution is to name the modules concerned and to set up the appropriate import/export structures.
You can use this page as a guide for setting up the module names and import/export structures.
Related
I need some third-party c library to be imported into a low-level module. I'm following these instructions. It says that find_library() should help me find such a lib, excluding any lib prefix and .so suffix.
#next 2 lines just to test
test =find_library('spcm_linux')
print(test)
#this line below is the actual code
spcmDll = cdll.LoadLibrary("libspcm_linux.so")
Returns:
None
OSError: spcm_linux.so: cannot open shared object file: No such file or directory
My library lives at:
/usr/lib/gcc/x86_64-linux-gnu/libspcm_linux.so
Reading about find_library() from the docs, it tells me that I can set an environment variable to add an environement variable (LD_LIBRARY_PATH). So in /etc/environement I have:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
PYTHONPATH="/home/fv/.local/lib/python3.6/site-packages"
LD_LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu"
I restart, try and it still doesn't work (same error message).
Any other way to "find" my library? Could put it in my program.py directory directly & import it some other way?
EDIT:
However, it does find libgomp.so.1, which is in the exact same folder as the library I'm trying to load. If that helps...
Turns out the root of the issue was rights.
Rights to the libspcm_linux.so lib weren't set properly and thus the script had no access rights to it.
However, the error that popped up was still about No such file or directory. I presume this is because it's a C library, which ctypes tried to load. It couldn't load it (because it didn't have the rights to it) however apparently it didn't see it fit to propagate the error (or couldn't because of some technicalities of how C code is loaded, perhaps).
Therefore from it's point of view, it couldn't load the requested library, and told me so - "No such file or..." even if this hide the real cause of the problem.
import pocketsphinx
for phrase in pocketsphinx.LiveSpeech():print(phrase)
So the weirdest thing ever happened. This code worked fine. Then I cut and pasted it into another python file in the same project and boom I get, AttributeError: module 'pocketsphinx' has no attribute 'LiveSpeech'. pocketsphinx is in my external libraries and my ide recognizes it, but now there is no autocomplete options with pocketsphinx.(should have recommendations). So this is weird. When I cut and past back to old file it does not work either now. ??? Hmm... Why
This kind of error often happens when there is a module in the project directory with the same name as the one being imported. This file is then found earlier when traversing sys.path, so it shadows the library you're trying to import.
So in this case you probably have a file pocketsphinx.py within your project directory. If you rename that to something else then it should work.
I have
root/Main.hs :
import ADT.Stack
main :: IO ()
main =
putStrLn "Hi"
root/ADT/Stack.hs
module Stack (Stack, empty, isEmpty, push, top, pop) where
...
Upon loading Main.hs, I have the error
File name does not match module name: …
Saw: ‘Stack’
Expected: ‘ADT.Stack’
If I change the module name to ADT.Stack in Stack.hs, I can get rid of the error.
However, I dont understand the reason behind such constraint.
Is there no way to avoid specifying in the code of Stack.hs what is already encoded in the name of the directory in which it is contained ?
If there are no alternative way, is there any good reason this ?
If you're using the hierarchical namespaces, your module names should reflect the full path. So, in root/ADT/Stack.hs, you should have
module ADT.Stack (Stack, empty, isEmpty, push, top, pop) where
After that, as you have observed, everything should be fine.
I am not aware of any possibility to derive the module name not only from the name you give it in the file, but also on the location of the file. (That is what you are after, aren't you?) Of course, this should be possible with some fancy preprocessing, but you probably don't want to go there.
So, then, why are things like they are? Not sure whether, for you, it qualifies as a good reason, but one can argue that this scheme has as an advantage that by simply moving a file to another directory you don't silently break any client codes. Instead, you get an error already when compiling the moved file.
The redundancy in the file location and the module name allows processors to find imported modules with only a minimal set of "search paths". Also, it provides a standard for organising source files over larger projects.
So far I've seen the answer for Python2 however it doesn't work on Python3, I want to be able to always get the latest changes in a module that lives in a package every time the code runs without reopening a new interpreter every time. Since modules seems to be loaded just once for performance purposes as specified in documentation,I would like to be able to force a load in the modules programatically right before starting my program. Thanks in advance...
Although I'm not a fan of answering my own questions, I think in this case totally worth to mention it since seems to be quiet useful, in order to reload a module that you previously modified without having to restart the whole interpreter, just programatically forcing the modules (contained within a package) to get the latest changes this is the way to go:
import com.your.package.YourModule as MyModuleInPackage
import imp
imp.reload(MyModuleInPackage)
Notice that trying to use imp.reload(com.your.package.YourModule) causes an error, so the way to go is by having an Alias for the fully quialified name of the module and use it in the reload function to work properly...
Hope this helps.
Regards!
What is a good strategy for stopping a requireJS module from loading from information you won't know until run-time?
The scheme I came up with involves using a loader plug-in that checks some run-time attributes and checks the "protected" modules against their attribute lists, and if they're not supposed to load, doesn't call load() from inside the loader plug-in load() function. However, this results in a browser error, which in older versions of IE, cause actual script errors, which is not what I want/need (it's actually a time-out error because load() is never called).
Is there a way to say, "Yeah, I got that you wanted to load this, but, um, we don't want to, and that's not an error, so go about your business with the rest of your loading business." Or perhaps a better scheme to achieve what I want?
I solved this by doing load(null) and checking for null in the places where the module that could possibly not be loaded is referenced.