I'm using the 64-bit version of python 3.3 and cython 0.18 on Windows 7.
I've encountered a problem that is thoroughly described here
One issue that was not discussed in the linked thread was, that the python's distutils called the link command (link.exe) with an option to export (this is only needed on Windows) a symbol named PyInit_[module name] but, if the module name was __init__ the cython-created C file only specified a symbol with name PyInit_[package name] and the linker gave back this error: LINK : error LNK2001: unresolved external symbol.
Fortunately, I managed to fix this issue in the build_ext module.
The problem that remains is that a compiled __init__.pyd module of mypackage containing an import statement like
import math
Throws an
SystemError: Parent module '' not loaded, cannot perform relative import
When mypackage is imported (no matter from where it is imported). Without import statements it works as expected though.
If anyone has a fix, workaround or information that could solve this problem or could explain why it's not (yet) solvable please, share your knowledge.
Related
I created a python extension using Boost::Python. To make it easier to use the extension on different target machines, I have included the libboost_python36.so.1.75.0 library in the same directory as the generated extension (pyshmringbuffer.so).
I checked out pyshmringbuffer.so and libboost_python36.so.1.75.0 onto a machine other than it was compiled in the directory : /path/to/pyshmringbuffer
After setting LD_LIBRARY_PATH to: /path/to/pyshmringbuffer and changing to this directory, I am able to run python3.6 and import the shared object just fine.
The problem comes when I try to run python from an alternate directory. From any other directory, I append the python path as follows:
import sys
sys.path.append("/path/to/pyshmringbuffer")
Then, when I try to import pyshmringbuffer, I get the following undefined symbol:
ImportError: /path/to/pyshmringbuffer/pyshmringbuffer.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
I was under the impression that all symbols are self contained within the shared object. Why does it matter where I import the shared library from?
The symbol in your error message is an internal one, generated by one of the build tools. Having one undefined suggests that one of your components was built with an incompatible tool version, or that a *.so file (shared object) is out of date in some other fashion.
The simplest way to fix this is usually to rebuild your product components from scratch, in the proper order.
I was able to resolve my issue by prepending /path/to/pyshmringbuffer to my python path using:
sys.path.insert(0,"/path/to/pyshmringbuffer")
I can't say for sure, but as #PRUNE pointed out, there is something in my python path that python is seeing before it sees the intended library.
Coincidentally, I DO have a build of libboost_python36.so.1.75.0 located elsewhere on the target machine. The path for this doesn't appear on my PYTHONPATH or LD_LIBRARY_PATH, so I wouldn't EXPECT it to have been interfering, but I can't be positive.
It's a small annoyance, but, pywin32 modules get reported as unresolved imports by the python linter in VSCode.
I've got pywin32 installed, and I'm able to import the module(s) in a terminal session, and when the script runs.
My python.pythonPath is set correctly in my settings.json.
The linter just can't seem to find the modules.
But if I use the following syntax the linter works, but the import obviously fails at run time.
import win32.lib.win32event
Any ideas on how I can "make" VSCode or the linter match the correct import?
Pylint has a configuration file, loaded by the command-line switch --rcfile. One of the entries in the configuration file is ignored-modules=. A comment line describes this option as a "list of module names for which member attributes should not be checked". There are several other options that are similar.
These options are needed because pylint is a static type checker, meaning that it doesn't load the module but merely inspects its source code. In the case of a module like the win32 collection, it uses .dll files that pylint cannot inspect. Therefore there is no way that pylint can figure out what names are exposed by win32. So the best you can do is tell pylint to suppress error messages.
The stacktrace is pretty clear about the cause of the error. But I am unable to figure about the root cause. I have a package abc and there is a module inside the package called abc.py. In abc.py, I have defined Flags . When I run the code, I get an error saying DuplicateFlag Error: The flag 'config' is defined twice: First from abc, Second from abc/abc.py.
I havenot imported the module abc.py in other files. Can a python expert tell me what could be the issue?
I am not sure what is causing the issue. But the fix for it is to delete all the attribute in the flags before you actually define the flags using the following code:
for name in list(flags.FLAGS):
delattr(flags.FLAGS,name)
I hope this helps. Anybody who know the actual cause of the issue is welcome to answer it for precisely.
UPDATE: The cause is partly answered in this Running a module in a package, importing a subpackage . The takeaway is : If you're running the module as a script a lot, you probably should make a new top-level script module that import the module from the package and runs the desired code . This prevents the module full of code from potentially existing twice, and also lets you benefit from cached bytecode being loaded from a .pyc file (which may make your program a bit faster to start up).
My package had cyclic dependency. Hence that could be the issue. I didnot even need to delete the attribute after i move my main script out of the package and run it normally.
Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.
I'm usually not working with Python (but have ability to read the code).
I'm trying to use csjark.
All the dependencies were installed correctly.
When executing csjark.py I'm receiving following error:
NameError name 'Platform' is not defined
The import is done with from platform import Platform
All the *.py files are located in the same folder.
I don't have any issue similar statements for other imports.
Importing with import platform is working, but latter I can't use any parameter from the class.
Please suggest ways to resolve the issue with the platform.py file.
Maybe your program is importing the wrong platform.py, for example this one:
https://docs.python.org/2/library/platform.html
which doesn't seem to have a Platform class. Try renaming the platform.py to something else and importing from that to see if this is the issue.