Python module created with Boost.Python won't be imported - python

I have a big C++ module with Python 3 bindings using Boost.Python, that I compile to a .so file using CMake on macOS.
When I try to import it in the REPL, everything seems to work fine:
>>>import myModule
>>>
However, as soon as I run the import statement, the famous rocket icon of Python shows up in the Dock and stays there jumping for some minutes and stops after. Obviously then, I cannot access any of the functions defined in my module, so the import looks fine but doesn't actually do anything.
I tried looking in the Console and saw that whenever I import myModule, I get two launchservicesd[83]: SecTaskLoadEntitlements failed error=22.
It brought me to this and that related questions but I can't find what the exact problem is.
The C++ module is huge so I just can't look at the code and find the problem, thus I'm asking for any hints about at least how to debug that problem.

I can suggest the following steps:
Try to import that module though local python session. So, run interactive python interpreter, and 'import myModule'.
If bad, try to check:
are python version, with which myMoudle was linked with, is similiar to used interpreter
check that build architectires are the same
check that you can load even simple boost.python example module
If ok, check that you have correctly set up module search path in your python code.

Related

Cannot import eurostag.dll into Python

I am new with programming, so it is maybe harder for me to understand but I have the following issue:
I have a script that imports "eurostag.dll", which according to its manual, should work until Python 3.6. (but the manual is not updated, so it may work also with later updates, I assume).\ The issue is that I have Python 3.8. and when running the script I receive the following message:
"Failed to load EUROSTAG library (Could not find module 'D:\Eurostag\eustag_esg.dll' (or one of its dependencies). Try using the full path with constructor syntax.)"
I have tried to move the .dll library where the script is, but nothing changed. I tried also changing the directory with os.chdir, but the same message appears (with the same 'D:\Eurostag\eustag_esg.dll', so the directory was not changed.
Does anybody know if there is any workaround for this?
Thank you!

vscode note recognising imported libraries for python and c++ despite code working

Recently set up c++, noticed that the #include <library> were underlined.
error read: library.h file can not be accessed
despite this the code still ran, recently start a new python project and same thing, vscode doesnt recognise my imported modules but despite this the code runs fine.
Anyone know the source of this?
note: when setting up c++ I initially installed minGW but ran into some errors so I switched to MSYS2 (uninstalled and removed path variables for minGW) which works but has the aforementioned error.
New approach:
changed import, and modified pylint error. Also something that I didnt mention some code does not have an error associated with it even though it doesn't seem to be any different to lines that do.
Note: I can no longer access RLEACCEL var with the new import method (not a big deal as it is not necessary)
Note: had to delete c++ links as I'm limited with how many links my post can have
new python import
disabled pylint error (I think)
error for pygame.init()
example of code that has no associated errors
modification of code to use new locals import
errors still showing up
python imported libraries
logged errors for python
About Python:
The reason why the terminal displays "No name'K_UP' in module'pygame.locals" is that "K_UP, K_DOWN, K_w, K_s, " these are constants of "locals.py" of module "pygame".
Usually, Pylint recognizes imported statements in VSCode as importing files or methods or classes in files.
1).When we import the pygame.locals module, these constants have already been imported into the program, so we can use from pygame import locals.
2).Since the code can be executed, we can also turn off such notifications of "pylint": (no-name-in-module)
"python.linting.pylintArgs": [
"--disable=E0611"
],
2.About C++:
Please check if the following settings are used in "settings.json":
"C_Cpp.default.includePath": ["..."],
"C_Cpp.default.systemIncludePath": ["..."],
Reference: #include errors detected. Please update your includePath.

Python: Can't Find Module When Running Script Within a Script

I created a Python program A for which I later wrote another Python program B that called A using the subprocess library. I had a module foo installed in A which worked perfectly fine until I started calling the program from B. Now, I get the error:
ImportError: no module named foo
when B is called. I am sure that the module is installed correctly, because when I enter a python shell from the same directory as A and B, I am able to import foo and use its functions successfully. So, why wouldn't foo import correctly in this situation?
EDIT
I call program B from program A using the following call.
call(["python", "levMap9.py", inputFilePath, outputFilePath, scalingFactor])
In program B (levMap9.py), I make the following import, which gives the import error for some reason
import Levenshtein as LV
EDIT2
I realize that it is probably worth mentioning that these programs worked fine when I initially developed them on OSX, but now are having this problem on a Windows 8 machine.
I tried adding the path to the Levenshtein module in PYTHONPATH (it already existed in PATH), and that solved my problem; though I don't entirely understand why. Thanks to those who contributed advice.
EDIT
Found the real answer to my problem here: How to execute Python scripts in Windows?

Problems importing a python module in Maya and it being recognized

Still learning certain things about Python... I am having issues recognizing my Python script in my scripts dir. First, I checked to see that my path is set correctly:
import sys
for pythonPath in sys.path:
print pythonPath
And C:/Users/..../Documents/maya/2014-x64/scripts is listed, which is where I am placing swap.py
In Maya's script editor I am typing the following:
import swap
reload(swap)
swap.printSomething()
I get:
Error: AttributeError: file line 3: 'module' object has no attribute 'printSomething' #
If I take the same code and throw it into a package...
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
And then call this, it works...
import swapPackage.swap as swap
reload(swap)
swap.printSomething()
Why? I am totally confused. Mel scripts even run fine from this location as well. I just can't get a simple python script to import and run.
Also something I noticed. Even though I can get this script to run in a package, the package name must be totally different than the module name. I can't have a package named this:
C:/Users/..../Documents/maya/2014-x64/scripts/swap/swap.py
but I can have one where the package name is different:
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
Ok folks, I was able to solve this by executing a print of my file, only to find out that it was sourcing a totally different version someone copied elsewhere. ARGH. This solves both issues, and makes sense why changing the package name from the module worked.
import swap
reload(swap)
print swap.__file__

Where should my Python 3 modules be?

I recently installed Python 3 on my Mac OSX 10.6.8 and I haven't had any problems with modules or imports until now. I'm writing a function that tests whether or not a triangle is right angled based on the length of the sides and the guide that the exercise was in has a bunch of equalities to test so I can see if it works:
testEqual(is_rightangled(1.5,2.0,2.5), True)
testEqual(is_rightangled(4.0,8.0,16.0), False)
testEqual(is_rightangled(4.1,8.2,9.1678787077), True)
testEqual(is_rightangled(4.1,8.2,9.16787), True)
testEqual(is_rightangled(4.1,8.2,9.168), False)
testEqual(is_rightangled(0.5,0.4,0.64031), True)
I should apparently import a function called testEqual(a,b,c) from a module called test, since the example programme in the guide starts with from test import testEqual, but when I typed that into my file I got this message:
from test import testEqual
ImportError: cannot import name testEqual
I suppose I should specify the path to the test module, but I can't find it my Python 3 library anywhere in my computer – just the 2.x ones that came installed with the computer, which are in /Library/Python. import turtle and import math worked, so it must be somewhere.
The test module in the Python stdlib doesn't contain a function called testEqual(). Its documentation starts with
Note: The test package is meant for internal use by Python only. It is
documented for the benefit of the core developers of Python. Any use
of this package outside of Python’s standard library is discouraged as
code mentioned here can change or be removed without notice between
releases of Python.
Are you sure that this guide you're following doesn't have its own test.py program that you're supposed to use instead?
When you write your testEqual() function make note of the directory you are working in. For instance on my mac I created a directory (folder) in documents so my path looks like: /Users/myName/Documents/python. Save your function (module) as testEqual.py and when you write you test.py script import testEqual after the shebang line. Once you have your scripts debugged your modules will be in a folder that python creates titled pycache don't remove that as it is compiled code. Now, as long as you are working in the same dir as your module you should not need to do anything other than use the import statement.

Categories