I just created a Python module from C++ with Boost.Python. It seems to work fine. The only thing which annoys me a bit is when I import it in PyCharm, it underlines the name of the module with red color. When I run the script, everything works fine.
Sure, I can ignore the unresolved reference, but that is not what I want because I would like the whisperer to work.
My question is: Is it even possible to "teach" PyCharm to whisper function, classes etc. of my module? And if so, how?
Related
I do have a strange behavior with a flutter package I am building. It uses FFI to integrate a custom-made c++ library.
When I run flutter run -d windows --release the code starts and I do have the window with the code running.
However, when I go to the directory where the executable is stored and I run it, the program starts but the library is not loaded. I do see also that when I run flutter test, it complains that it cannot load the library. I have checked that the dll's needed are there using dependenciesGUI.exe and it seems that everything is fine, at least on my side. I do see however that within kernel32.dll I am missing ext-ms-win-oobe-query-l1-1-0.dll.
I am using Visual Studio 2022 with the x64 configuration.
Any idea on what could be the issue? For me it is VERY puzzling to be able to run the software through flutter but not with the executable directly.
Thanks!
Yours,
Pi-r
EDIT:
I compared my package with a fresh package built with flutter. With a fresh package, the behavior is the one expected: I can have the program run normally or with flutter run.
I compared the libraries of the clean package with the ones linked in my package. They are the same (with the same missing dlls which do not seem to pose an issue).
I also checked that the exported functions I needed where present -> It is the case.
The only difference I can see is that using flutter run adds a series of libraries to the path. Has I am a Linux person, I do not know of a tool that could be used to detect what is the missing library. I am open to write a separated c++ code that would load the library if it could help me identify what is the issue... ANY tips/tricks would be greatly appreciated :)
I finally found the issue I had and it is related to a different behavior under Linux and under Windows (as you will guess, I am a Linux person).
When compiled under Linux, I can force the compiler to link multiple libraries relatively to my main library. I discovered that this is not the case under Windows. Either the dlls are in the executable folder or in the Path.
For the sake of code clarity, my package uses two different libraries. Library A, which is compiled from flutter with the ffi package, called library B. First the second library was in the asset folder and with the relative linking of Linux, it was working perfectly. But it did not work under Windows until I explicitly copied the two in the same directory of the executable.
The solution was then to ensure that both libraries are copied correctly in the directory of the flutter executable. This can be done easily if you add the dependent libraries to the bundle variable in the CMakeLists.txt of the package.
However, this doesn't work when you do the testing (flutter test). As the bundle mechanism seems to be not propagated to the test function. Therefore here, the only solution is to copy the dependent libraries to the root directory of the source code :vomiting_face:
I must point out that this is only the case under Windows, for Linux, it works out of the box...
I have written a BPF program that I can install using gobpf, i.e. using their bcc tooling. While this works alright from a main package, this breaks as soon as I move it into a package for importing it as a module.
To clarify: It works with all code in package main, but as soon as I rename the package and move the main() to cmd/command.go it stops working with go run complaining that it can't find an included lib (bcc/proto.h). Incidentally, this is the same error as I always got when running gcc on my .c file without any indication I want to use BPF (the part that gobpf did for me, until I moved its invocation to a module...).
I realize this is question very specific and sits in a weird place between Go, CGo, the way C and C++ handle includes, BPF, and bcc, but I am at a loss here.
You can check out my code here https://github.com/bwNetFlow/bpfdump if that helps. It needs bcc installed in addition to go run doing its thing. Basically:
HEAD is the modularized version that does not work (go run cmd/dump.go)
HEAD~ is my initial experiment that does work (go run bpfdump.go) (you'll get an permission error as user, which is fine as it has compiled anyways).
PS: I think it might have to do with this (rather creative?) construction of bcc/proto.h: https://github.com/iovisor/bcc/blob/master/src/cc/exported_files.cc
I have a problem with my PyCharm. After I updated Python from 3.3.5 to 3.4, I have an annoying error in PyCharm of the following form:
from multiprocessing import Queue, Process
PyCharm underlines Queue and Process in red and shows an unresolved reference. The code actually runs fine both in the command line and inside PyCharm. Code completion seems to be broken too for these classes.
I am suspecting a problem with PYTHONPATH, but I'm not sure how to solve it.
System details: Mac OS X 10.9.2, Python 3.4 installed through Homebrew, Pycharm 3.1.1
It's not a problem with PYTHONPATH. If we look in multiprocessing\__init__.py, we see the following:
#
# Copy stuff from default context
#
globals().update((name, getattr(context._default_context, name))
for name in context._default_context.__all__)
__all__ = context._default_context.__all__
Notably there is nothing in the file that looks like Queue, Process, etc.
Now what is this context._default_context? If we look in multiprocessing\context.py, we see
class BaseContext(object):
...
def Queue(self, maxsize=0):
'''Returns a queue object'''
from .queues import Queue
return Queue(maxsize, ctx=self.get_context())
So in reality, Queue is never defined in the module itself, but rather through some dynamic code, it gets set correctly at runtime depending on the user's operating system. This is why Pycharm doesn't know that there are Queue and Process classes in the multiprocessing module.
Maybe you can file a bug report and try to get them to selectively run code to figure out these dynamic names or to make an exception here and put some workaround that tells Pycharm that there are in fact Queue/Process classes, but that seems like it would be low on their priority list. So you'll just have to live with it, probably. (In the same boat here)
I'd definitely report an issue with JetBrains if one doesn't already exist, but I would not suggest downgrading Python merely due to your IDE not interpreting an import as expected (the actual interpreter still works).
I have the same issue, simply adding # noinspection PyUnresolvedReferences above the unresolved references silences the compiler 'errors'. Of course I'd love this to be fixed and will remove the # noinspection lines once it is, but it certainly won't stop me from writing code using PyCharm and Python 3.4.
Edit: Looks like someone reported it: http://youtrack.jetbrains.com/issue/PY-12860
Edit: Reportedly fixed in build 138.913
I have had the same issue. If you are using python 3.4.4, please try this:
from queue import Queue
You can read more here: https://docs.python.org/3.4/library/queue.html
I downloaded everything described as in pygtk for installation. Everything went fine until when I tried to type "import gtk", it threw an ImportError as follows:
from gtk import _gtk
ImportError: DLL load failed: ...(something unreadable)
Then I re-install the pygtk-2.22.0 again, the same problem existed. So what to do please? Thanks in advance!
The error you describe is usually caused by the python bindings (pygtk/pygobject/pycairo) being unable to load a dll it needs to function properly. Most of those errors are either caused by:
the GTK+ runtime not being on your PATH environment variable. This has long been
the advice on how to get pygtk working on Windows. Please don't change your user
or system PATH environment variable, it is no longer needed with the all-in-one
installer.
multiple GTK+ runtime versions are on your PATH environment variable and the first
(leftmost) one is not compatible with the pygtk/pygobject/pycairo versions you use.
This is why adding the GTK+ runtime to your PATH environment variable is a bad idea:
it is easy to mix up versions (sometimes GTK+ related installers add their bin
directory to PATH on installation which contains an older or incomplete runtime).
a rare case where some software package installed libintl.dll and iconv.dll into
%WINDIR%\system or %WINDIR%\sytem32
The most straightforward way to avoid the dll hell described above is to use the
PyGTK All-in-one installer (http://download.gnome.org/binaries/win32/pygtk/2.22/).
It contains both the Python bindings, the GTK+ runtime and even Glade and does
no longer require you to change the PATH environment variable.
Small warning: if you decide to use the all-in-one installer, you'll have to uninstall
the separate pygtk/pygobject/pycairo packages you've used before (or you'll be in
a world of trouble...)
read the source code, perhaps there is a need for a specific version of pygtk
edit the source code to work with your pygtk version
I had this issue as well. You didn't mention for sure in your answer, so I'll suggest the obvious (well...the obvious to people that have used it a while, perhaps). Did you use the following three lines of code to import? You have to use these, in order, to import PyGTK.
I'm assuming your version here is 2.24 like mine. If not, change it to the version you have.
import pygtk
pygtk.require('2.24')
import gtk
That should suffice in importing gtk.
Problem
As others have noted, don't put gtk in the path. I know, its tempting, and it works for XYZ, but it (to say the least) gets confusing. Dependency hell is bad enough on a platform like Linux which tries to make it easy for you.
For clarification, what the PyGTK All In One does for you is to install (what appears to be) a full gtk+ runtime directly in your python packages folder, so e.g. in C:\Python\Lib\site-packages\gtk-2.0\runtime
Solution
NOTE: %YOURPYTHONPATH% is an EXAMPLE variable which contains the path of your Python installation (e.g. C:\Python, or C:\Python27, or whatever it actually is). I suggest setting %PYTHON_DIR% or %PYTHON_PATH% if you want to use a variable to do this, as more programs are likely to use this.
To get your XYZ program requiring GTK to work, add %YOURPYTHONPATH%\Lib\site-packages\gtk-2.0\runtime\bin to the PATH when running your program; the correct versions of the DLLs it needs to link against are in that folder. All other GTK+ runtimes I had installed (GTK+/GTK2-Runetime) gave me errors.
Again; Do not attempt to set a user or system level variable (don't open up the dialog pictured below) as this will likely cause problems for you later unless you VERY sure you know what you are doing. If you are reading this, you most likely don't know as much as you think you do. Instead, alter the path in a cmd prompt, or use a batch/script file to set it up for you.
After you install the pygtk.org package, install each of these in the following order:
pycairo-1.8.6.win32-py2.6.exe
pygobject-2.20.0.win32-py2.6.exe
pygtk-2.16.0+glade.win32-py2.6.exe
gtk+-bundle_2.16.6-20100912_win32.zip
For more information:
http://freetstar.com/windows7-pygtk-gtk/
I got the secusses according the link on my PC.
Firstly, I come from Windows-VisualStudio-C++ background. Now I am developing in a Ubuntu environment.
With the help of a Makefile, I built a mymodule.so and copied it to the modules folder within apache. Now, it appears that the module is working fine. But I would like to debug into this module to understand it better.
So, first, is there any way I can get something similar to the Visual Studio debugger type of feel while debugging this module?
Now, i read that i can use gdb to debug into apache modules, can somebody tell me in detail how this is done or point me to some resource that does it.
Ideally, i would like to single step and stuff. I am trying Code::Blocks IDE which has some debugging support. Using the IDE and custom make file, I build the module. Copied it to module location, but how do i debug.
How do i hook to the apache process. Should I use Attach to Process. I tried that with the pid of httpd, but with no success.
Also, while building is there some flag that i should set so that the .so file is debuggable?
I am pretty basic with Linux because i come from windows programming background. Kindly suggest how I go about this.
Thanks in advance,
Arjun
I think you can attach to an apache process using gdb (at 1111, where 1111 is the PID of the process, or in Code::Blocks) and set breakpoints in your module functions, if the module was compiled with debug. You will need to be root or the same user as the apache process.
gcc -g flag is used to build binaries with the debug info.